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 reading an XML document from file input stream.
//Reads and parses the XML
Document doc = builder.build(ins);
Element root = doc.getRootElement();
System.out.println("Root Node : " + root.getLocalName());
//Get children
Elements students = root.getChildElements();
Element nameChild = null; for (int i = 0 ; i < students.size() ; i ++) {
System.out.println(" Child : " + students.get(i).getLocalName());
//Get first child with tag name as 'name'
nameChild = students.get(i).getFirstChildElement("name"); if (nameChild != null) {
System.out.println(" Name : " + nameChild.getValue());
}
}
}