Do XPath on a Node with Java
I have someNode and I'd like to do XPath on it like this:
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expr = xpath.compile("//name");
Object result = expr.evaluate(SOMETHING_ELSE, XPathConstants.NODE);
How can I turn someNode to SOMETHING_ELSE and do my开发者_高级运维 XPath?
What is wrong with Object result = expr.evaluate(someNode, XPathConstants.NODE);
? The XPathExpression takes an Object as first parameter, and you can pass any reference to a node, element or attribute of your XML document.
精彩评论