List of usage examples for javax.xml.xpath XPathConstants STRING
QName STRING
To view the source code for javax.xml.xpath XPathConstants STRING.
Click Source Link
The XPath 1.0 string data type.
Maps to Java String .
From source file:Main.java
public static String retrieveElementByXMLtag(String xPathExpression) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xpath.compile(xPathExpression); return expr.evaluate(doc, XPathConstants.STRING).toString(); }
From source file:Main.java
public static String getValueByXpath(Node doc, String xquery) { try {//from w w w. j a v a 2s . c om XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); XPathExpression expression = xpath.compile(xquery); String result = (String) expression.evaluate(doc, XPathConstants.STRING); return result; } catch (Exception e) { } return null; }
From source file:Main.java
public static String evalXPathString(String xpath, Node source) throws XPathExpressionException { return (String) newXPath(xpath).evaluate(source, XPathConstants.STRING); }
From source file:Main.java
public static String selectXPathString(final String xPath, final Node inNode, final String nsuri, final String pre) throws Exception { return (String) getNodesListXpath(xPath, inNode, nsuri, pre, XPathConstants.STRING); }
From source file:Main.java
/*** * Returns the string value of evaluated xpath * * @param document - XML Document to check * @param xpathString - xpath to evaluate * @return String evaluation of the xpath *//*from w w w . j ava2 s . co m*/ public static String getValueFromXPath(Document document, String xpathString) { try { return (String) XPathFactory.newInstance().newXPath().evaluate(xpathString, document, XPathConstants.STRING); } catch (XPathExpressionException e) { throw new RuntimeException("Error evaluating xpath [" + xpathString + "] -- " + e.getMessage()); } }
From source file:Main.java
/** * This method uses XPath to get you the String from the provided node. * @param parentNode The Node to start at. * @param expression The XPath Expression to evaluate. * @return The String that you want to extract using the XPath expression. * @throws XPathExpressionException/*w ww .ja v a 2 s. co m*/ * * @author <a href='mailto:intere@gmail.com'>Eric Internicola</a> */ public static String getString(Node parentNode, String expression) throws XPathExpressionException { return (String) getXPath().evaluate(expression, parentNode, XPathConstants.STRING); }
From source file:Main.java
public static String getStringContentByXPath(Node parentNode, NamespaceContext context, String xPathExpression) throws XPathExpressionException { return (String) getByXPath(parentNode, context, xPathExpression, XPathConstants.STRING); }
From source file:Main.java
/** * Extract a String node from an XML Message * * @param xpath XPath object/*from ww w . java 2 s.c o m*/ * @param nodePath XPath statement to locate the node * @param xmlString Xml string object to extract the data from * @return The requested data, or "" if not found. */ public static String extractNode(XPath xpath, String nodePath, String xmlString) { InputSource inputSource = new InputSource(new StringReader(xmlString)); try { return (String) xpath.evaluate(nodePath, inputSource, XPathConstants.STRING); } catch (XPathExpressionException e) { return ""; } }
From source file:Main.java
public static String getFirstValueFromXPath(Document parent, String xpath) throws Exception { try {// ww w.ja v a 2s . c o m XPath xPath = XPathFactory.newInstance().newXPath(); return (String) xPath.compile(xpath).evaluate(parent, XPathConstants.STRING); } catch (XPathExpressionException xpee) { throw new Exception(xpee.getMessage()); } }
From source file:Main.java
public static String getValueAsString(String filePath, String value) throws ParserConfigurationException, SAXException, IOException { String id = null;/* ww w . ja v a 2 s .co m*/ XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xpath = xpathFactory.newXPath(); try { XPathExpression expr = xpath.compile(value); id = (String) expr.evaluate(getDoc(filePath), XPathConstants.STRING); } catch (XPathExpressionException e) { e.printStackTrace(); } return id; }