XOM (XML Object Model) is a tree based java API for processing XML
by taking the best ideas from SAX and DOM. It is simple, fast and easy to use.
This requires the library xom-1.2.7.jar to be in classpath.
The following example shows querying an XML document using XPath expression.
//Reads and parses the XML
Document doc = builder.build(ins);
//Selects the first two Numbers that are children of the RandomNumbers element
//It uses 1 - based index not 0 - based
Nodes nums = doc.query("//RandomNumbers/Number[position() < 3]");
for (int i = 0 ; i < nums.size() ; i ++) {
System.out.println(nums.get(i).getValue());
}
}