XPathGen Released

I’ve just released XPathGen, a simple utility class for generating XPath paths that uniquely identify DOM Nodes in Java.

For example:

Document testDoc = createDocument(
"<a>aa<b attr='test'>b<!-- comment -->c<c/></b>d</a>");

//Grab text node "aa"
Node aa = testDoc.getDocumentElement().getFirstChild();

//Should print "/node()[1]/node()[1]"

I pulled this code out of diffxml and re-licensed it under the Apache licence, so that it can be used more freely.

(This was mainly prompted by this StackOverflow question).

Grab it from github if you’re interested.

Leave a Reply