Wednesday, June 26, 2013

Java; parse XML using XPath

Nice XML parser I found that uses XPath to extract data.  I'm using it in my unit testing.

• Select XML nodes using XPath and a single line of Java code
https://github.com/gioele/xpathapi-jaxp

E.g.,
 
List<Node> bestFriends = XPathAPI.selectListOfNodes(doc, "//friend[@status='best']");
 
doc can be an instance of Document or Node.  This should help keep XPath references shorter since they can be relative to a Node instead of the top level Document.

What are other Java resources that also use XPath to isolate and extract data?

If you don't want to use XPath for data extraction, you could always use another library, like the DOM Parser.

No comments:

Post a Comment