List of usage examples for javax.xml.xpath XPathConstants NODESET
QName NODESET
To view the source code for javax.xml.xpath XPathConstants NODESET.
Click Source Link
The XPath 1.0 NodeSet data type.
Maps to Java org.w3c.dom.NodeList .
From source file:Main.java
public static String editPath(String xmlSource, String xPath, String newValue) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException, TransformerException {/*from w ww . ja va 2 s . co m*/ Document xmlDoc = readString(xmlSource); XPathExpression expr = evaluateThePath(xPath); NodeList nl = (NodeList) expr.evaluate(xmlDoc, XPathConstants.NODESET); for (int i = nl.getLength(); i > 0; i--) { nl.item(0).setNodeValue(newValue); } return xmlDocToString(xmlDoc); }
From source file:Main.java
public static Object execXpathGetNodeList(String srcXmlString, String xPath) { Object result = null;//w ww . j a v a 2 s.c om try { Document doc = stringToDoc(srcXmlString); XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); XPathExpression expr = xpath.compile(xPath); result = expr.evaluate(doc, XPathConstants.NODESET); } catch (Exception ex) { logger.error(ex); } return result; }
From source file:Main.java
public static NodeList getNodeList(Node node, String xPathAsString) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xpath.compile(xPathAsString); return (NodeList) expr.evaluate(node, XPathConstants.NODESET); }
From source file:Main.java
/** * @param node An XML DOM Tree for query * @param query An XPATH query to run against the DOM Tree * @param nc The namespaceContext that maps prefixes to XML namespace * @return A list of nodes that result from running the query against * the node./*w w w .j a v a 2s .co m*/ * @throws Exception If anything goes wrong. No error handling for brevity */ public static NodeList query(Node node, String query, NamespaceContext nc) throws Exception { XPathFactory xpf = XPathFactory.newInstance(); XPath xpath = xpf.newXPath(); xpath.setNamespaceContext(nc); return (NodeList) xpath.evaluate(query, node, XPathConstants.NODESET); }
From source file:Main.java
public static NodeList executePath(final Node node, final XPathExpression expression) throws XPathExpressionException { return (NodeList) expression.evaluate(node, XPathConstants.NODESET); }
From source file:Main.java
public static NodeList getValueAsNodes(String filePath, String value) throws ParserConfigurationException, SAXException, IOException { NodeList nodeList = null;/* w w w. j a v a 2 s.co m*/ XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xpath = xpathFactory.newXPath(); try { XPathExpression expr = xpath.compile(value); nodeList = (NodeList) expr.evaluate(getDoc(filePath), XPathConstants.NODESET); } catch (XPathExpressionException e) { e.printStackTrace(); } return nodeList; }
From source file:Main.java
public static NodeList getNodeList(Object node, XPathExpression expression) throws XPathExpressionException { return (NodeList) expression.evaluate(node, XPathConstants.NODESET); }
From source file:Main.java
public static NodeList getNodes(final Document doc, final String query) throws XPathExpressionException { final XPath xpath = XPathFactory.newInstance().newXPath(); final XPathExpression expr = xpath.compile(query); return (NodeList) expr.evaluate(doc, XPathConstants.NODESET); }
From source file:Main.java
public static NodeList evaluateXPathExpr(XPathExpression xpath, Node node) throws XPathExpressionException { return (NodeList) xpath.evaluate(node, XPathConstants.NODESET); }
From source file:Main.java
public static NodeList getNodes(Document doc, String query) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xpath.compile(query); Object result = expr.evaluate(doc, XPathConstants.NODESET); NodeList nodes = (NodeList) result; return nodes; }