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
static public NodeList getNodeList(Document doc, XPath xPath, String pattern) throws XPathExpressionException { XPathExpression expr;//from ww w. ja v a 2s .c o m NodeList nl; expr = xPath.compile(pattern); nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); return nl; }
From source file:Main.java
public static NodeList list(String path, Node e) { return (NodeList) evaluateXPath(path, e, XPathConstants.NODESET); }
From source file:Main.java
/** * Get nodelist from XML document using xpath expression * /*ww w. j a v a 2 s.c om*/ * @param doc * @param expression * @return * @throws XPathExpressionException */ public static NodeList getNodeList(final Document doc, final String expression) throws XPathExpressionException { if (null == expression || expression.isEmpty() || null == doc) { return null; } log.finer("Executing xpath xpression " + expression); XPath xPath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xPath.compile(expression); Object result = expr.evaluate(doc, XPathConstants.NODESET); return (NodeList) result; }
From source file:Main.java
public static List<Node> xpathToNodeList(String xpathQuery, Object domObject) throws XPathExpressionException { List<Node> result = new ArrayList<Node>(); XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xpath = xpathFactory.newXPath(); NodeList nodeList = (NodeList) xpath.evaluate(xpathQuery, domObject, XPathConstants.NODESET); for (int i = 0; i < nodeList.getLength(); i++) result.add(nodeList.item(i));//from ww w. ja v a 2s . co m return result; }
From source file:Main.java
public static NodeList evaluateXPathQuery(Document doc, NamespaceContext context, String xPathQuery) throws XPathExpressionException { XPathExpression expr = createXPathExpression(context, xPathQuery); return (NodeList) expr.evaluate(doc, XPathConstants.NODESET); }
From source file:Main.java
public static NodeList selectNodes(Node node, String express) { NodeList result = null;//w ww . j a v a 2 s. co m XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xpath = xpathFactory.newXPath(); try { result = (NodeList) xpath.evaluate(express, node, XPathConstants.NODESET); } catch (XPathExpressionException e) { e.printStackTrace(); } return result; }
From source file:Main.java
public static NodeList queryNodeList(Document document, String xPath) { try {/* w w w .j a v a 2 s. com*/ XPathExpression expr = XPathFactory.newInstance().newXPath().compile(xPath); return (NodeList) expr.evaluate(document, XPathConstants.NODESET); } catch (XPathExpressionException e) { throw new IllegalArgumentException(e); } }
From source file:Main.java
public static final List<Node> selectNodesViaXPath(XPath xPath, Node startingNode, String xPathExpression) throws XPathExpressionException { List<Node> data = new ArrayList<Node>(); XPathExpression expression = xPath.compile(xPathExpression); Object result = expression.evaluate(startingNode, XPathConstants.NODESET); NodeList nodeList = (NodeList) result; for (int index = 0; index < nodeList.getLength(); index++) { data.add(nodeList.item(index));/*from w w w.j a v a 2 s. c o m*/ } return data; }
From source file:Main.java
static public ArrayList<Element> selectElements(Element element, String xpathExpression) throws Exception { ArrayList<Element> resultVector = new ArrayList<Element>(); if (element == null) { return resultVector; }/*from w ww . j a v a 2 s . c o m*/ if (xpathExpression.indexOf("/") == -1) { NodeList nodeList = element.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(xpathExpression)) { resultVector.add((Element) node); } } } else { XPath xpath = XPathFactory.newInstance().newXPath(); NodeList nodes = (NodeList) xpath.evaluate(xpathExpression, element, XPathConstants.NODESET); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); resultVector.add((Element) node); } } return resultVector; }
From source file:Main.java
public static NodeList evalXPathAsNodeList(Object item, String xpath, XPathFactory factory) throws XPathExpressionException { XPath path = factory.newXPath(); XPathExpression expr = path.compile(xpath); return (NodeList) expr.evaluate(item, XPathConstants.NODESET); }