Skip to content

Instantly share code, notes, and snippets.

@deckerego
Created December 6, 2013 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deckerego/7825615 to your computer and use it in GitHub Desktop.
Save deckerego/7825615 to your computer and use it in GitHub Desktop.
Search an XML Document with dom4j
File file = new File("/path/to/file");
SAXReader reader = new SAXReader();
Document document = reader.read(file);
XPath pathSelector = DocumentHelper.createXPath("/root/childOne/leaf[@attributeName='attributeValue']");
List pathNodes = pathSelector.selectNodes(document);
for(Object pathNode : pathNodes) {
Element pathElement = (Element) pathNode;
System.out.println(pathElement.getTextTrim());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment