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 NodeList SelectNodes(Document doc, String xmlpath) { NodeList nodes = null;/* w w w . ja v a 2s .c om*/ Object result; try { XPathFactory xFactory = XPathFactory.newInstance(); XPath xpath = xFactory.newXPath(); XPathExpression expr; expr = xpath.compile(xmlpath); result = expr.evaluate(doc, XPathConstants.NODESET); nodes = (NodeList) result; } catch (XPathExpressionException e) { // TODO Auto-generated catch block e.printStackTrace(); } return nodes; }
From source file:Main.java
public static NodeList getChildNodesByExpression(Document doc, String expression) { try {//from w w w . ja v a 2 s.c om XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xpath.compile(expression); Object result = expr.evaluate(doc, XPathConstants.NODESET); return (NodeList) result; } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:Main.java
public static List<Element> getXPathList(Node node, String expr) { assertNotNull("node == null", node); XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); List<Element> result = new ArrayList<Element>(); try {//w ww. j av a 2s .c o m NodeList nl = (NodeList) xpath.evaluate(expr, node, XPathConstants.NODESET); for (int i = 0; i < nl.getLength(); i++) { result.add((Element) nl.item(i)); } return result; } catch (XPathExpressionException e) { throw new RuntimeException(e); } }
From source file:Main.java
/** * Return a list of elements based on xPath *///from w w w. ja va 2s . c om static NodeList getElementsByAttribute(Document doc, String xPath) { XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); XPathExpression expr = null; NodeList nl = null; try { expr = xpath.compile(xPath); nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); } catch (XPathExpressionException e) { e.printStackTrace(); } return nl; }
From source file:Main.java
static <T> List<T> xPathObjects(String expr, Object context) { try {//from w w w . j a v a2s. co m NodeList nodes = (NodeList) xPath().evaluate(expr, context, XPathConstants.NODESET); List<T> result = new ArrayList<T>(nodes.getLength()); for (int i = 0; i < nodes.getLength(); i++) result.add((T) nodes.item(i)); return result; } catch (XPathExpressionException e) { throw new IllegalArgumentException(e); } }
From source file:Main.java
public static List<String> xPathEvalList(String content, String expression) throws XPathExpressionException { List<String> retValues = new ArrayList<String>(); XPath xpath = XPathFactory.newInstance().newXPath(); InputSource inputSource = new InputSource(new StringReader(content)); NodeList ox = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET); for (int i = 0; i < ox.getLength(); i++) { retValues.add(ox.item(i).getNodeValue()); }/*from ww w . j a v a2s . com*/ return retValues; }
From source file:Main.java
public static NodeList evalXpath(InputStream xmlStream, String path) throws XPathExpressionException { InputSource inXML = new InputSource(xmlStream); XPathFactory xfactory = XPathFactory.newInstance(); XPath xpath = xfactory.newXPath(); XPathExpression expr = xpath.compile(path); Object result = expr.evaluate(inXML, XPathConstants.NODESET); return (NodeList) result; }
From source file:Main.java
public static NodeList getXpathExpressionNodeList(Object xprContext, String xpExpression) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression xpe = xpath.compile(xpExpression); NodeList nodes = (NodeList) xpe.evaluate(xprContext, XPathConstants.NODESET); return nodes; }
From source file:Main.java
/** * Return one element based on xPath/*from www .jav a 2 s .c om*/ */ static Element getElementByAttribute(Document doc, String xPath) { XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); XPathExpression expr = null; NodeList nl = null; try { expr = xpath.compile(xPath); nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); } catch (XPathExpressionException e) { e.printStackTrace(); } return (Element) nl.item(0); }
From source file:Main.java
public static List<Node> xPathEvalListNodes(String content, String expression) throws XPathExpressionException { List<Node> retValues = new ArrayList<Node>(); XPath xpath = XPathFactory.newInstance().newXPath(); InputSource inputSource = new InputSource(new StringReader(content)); NodeList ox = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET); for (int i = 0; i < ox.getLength(); i++) { retValues.add(ox.item(i));// ww w . ja va 2 s . c o m } return retValues; }