List of utility methods to do XPath Get
String | getString(final String xPath, final Object item) Evaluates the xpath on an object return (String) evaluateXPath(xPath, item, XPathConstants.STRING);
|
String | getString(Node node, XPathExpression expr) Get a string from an XPath expression. return (String) expr.evaluate(node, XPathConstants.STRING);
|
String | getStringByXPath(String xml, String xpathStr) Get a string by XPATH from a xml file Document doc = parseXML(xml); if (doc == null) return null; try { XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); XPathExpression expr = xpath.compile(xpathStr); return (String) expr.evaluate(doc); ... |
String | getStringValue(Node node, XPathExpression expression) Evaluates the XPath expression in the specified context and returns the found element as a String. try { return (String) expression.evaluate(node, XPathConstants.STRING); } catch (XPathExpressionException e) { return null; |
String | getStringValue(Object doc, XPathExpression path) get String Value return path.evaluate(doc);
|
String | getStringValue(String targetDoc, String xpathExp, String encoding) get String Value DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new ByteArrayInputStream(targetDoc.getBytes(encoding))); XPathFactory pathFactory = XPathFactory.newInstance(); XPath xpath = pathFactory.newXPath(); XPathExpression pathExpression = xpath.compile(xpathExp); String result = (String) pathExpression.evaluate(doc, XPathConstants.STRING); if (result != null) { result = result.trim(); ... |
String | getStringValueByXPath(Node node, String xPath) get String Value By X Path return path.evaluate(xPath, node);
|
String | getText(String xPathExpression, Node node) get Text XPath xpath = xPathFactory.newXPath();
return xpath.evaluate(xPathExpression, node);
|
String[] | getTextNodes(Node contextNode, String xPath) get Text Nodes return getTextNodes(contextNode, xPath, contextNode);
|
String | getValidXpath(String xPath, NamespaceContext context) get Valid Xpath if (context == null) return xPath; String namespaceURI = context.getNamespaceURI(DEFAULT_NS); if (namespaceURI != null && !namespaceURI.isEmpty()) { StringBuilder stringBuilder = new StringBuilder(); String[] tags = xPath.split("/"); int length = tags.length; for (int i = 0; i < length - 1; i++) { ... |