List of usage examples for javax.xml.xpath XPathConstants NODE
QName NODE
To view the source code for javax.xml.xpath XPathConstants NODE.
Click Source Link
The XPath 1.0 NodeSet data type.
From source file:Main.java
public static Node evalXPathNode(String xpath, Node source) throws XPathExpressionException { return (Node) newXPath(xpath).evaluate(source, XPathConstants.NODE); }
From source file:Main.java
public static Node selectSingleNode(final String xPath, final Node inNode, final String nsuri, final String pre) throws Exception { return (Node) getNodesListXpath(xPath, inNode, nsuri, pre, XPathConstants.NODE); }
From source file:Main.java
public static Element evalXPathElement(String xpath, Node source) throws XPathExpressionException { return (Element) newXPath(xpath).evaluate(source, XPathConstants.NODE); }
From source file:Main.java
private static Node getNodeById(Document doc, String id) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xpath.compile("//" + MESSAGE + "[@id='" + id + "']"); return (Node) expr.evaluate(doc, XPathConstants.NODE); }
From source file:Main.java
public static Node getChildNode(Document doc, String parentTag, String childnode) { try {// ww w. ja v a2s. co m XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xpath.compile("//" + parentTag + "/" + childnode); Object obj = expr.evaluate(doc, XPathConstants.NODE); return obj != null ? (Node) obj : null; } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:Main.java
public static Node getXpathExpressionNode(Object xprContext, String xpExpression) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression xpe = xpath.compile(xpExpression); Node node = (Node) xpe.evaluate(xprContext, XPathConstants.NODE); return node;//from w w w. j av a2s . c om }
From source file:Main.java
public static String getXpathExpressionValue(Object xprContext, String xpExpression) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression xpe = xpath.compile(xpExpression); Node valueNode = (Node) xpe.evaluate(xprContext, XPathConstants.NODE); String value = null;/*from w w w . j ava 2s . c om*/ if (valueNode != null) value = valueNode.getNodeValue(); if (value != null) { // if the node is a text node - then we trim and (potentially) look for CDATA if (valueNode.getNodeType() == Node.TEXT_NODE) { value = value.trim(); // look for CDATA if we got nothing (stupid whitespace) if (value.length() == 0) { Node siblingForCDATA = valueNode.getNextSibling(); if (siblingForCDATA.getNodeType() == Node.CDATA_SECTION_NODE) { value = siblingForCDATA.getNodeValue(); } } } } return value; }
From source file:Main.java
/** * This method uses XPath to get you a child node of the provided node. * @param parentNode The node to start at. * @param expression The XPath Expression to evaluate. * @return The Node that was retrieved by the provided node and xpath expression. * @throws XPathExpressionException// w w w .j av a 2 s. c o m * * @author <a href='mailto:intere@gmail.com'>Eric Internicola</a> */ public static Node getNode(Node parentNode, String expression) throws XPathExpressionException { return (Node) getXPath().evaluate(expression, parentNode, XPathConstants.NODE); }
From source file:Main.java
/** * Returns a single node that matches the given XPath expression. * // w ww .jav a 2 s . c om * @param doc * Document that contains the nodes. * @param expression * XPath expression to be matched. * @return Returns a single node matching the given expression. */ public static Node selectSingleNode(Document doc, String expression) { try { XPath xpath = XPathFactory.newInstance().newXPath(); return (Node) xpath.evaluate(expression, doc, XPathConstants.NODE); } catch (XPathExpressionException e) { // ignore } return null; }
From source file:Main.java
public static Node getSingleNode(InputStream is, String xpathStr) throws SAXException, IOException, XPathExpressionException { Node result = null;/*from w w w .j a v a2 s . c om*/ Document doc = null; doc = dombuilder.parse(is); //"//db/@dbType" result = (Node) xpath.compile(xpathStr).evaluate(doc, XPathConstants.NODE); return result; }