开发者

Do XPath on a Node with Java

开发者 https://www.devze.com 2022-12-19 12:40 出处:网络
I have someNode and I\'d like to do XPath on it like this: XPath xpath = XPathFactory.newInstance().newXPath();

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消