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 inserting a comment as child of an existing element.
//Reads and parses the XML
Document doc = builder.build(ins);
Element root = doc.getRootElement();
//Add comment as first child of root element
Comment listComment = new Comment("List of students");
root.insertChild(listComment, 0); //insert comment as first child of root
//Get children
Elements students = root.getChildElements();
Comment nameComment = null; for (int i = 0 ; i < students.size() ; i ++) {
nameComment = new Comment("Student name");
students.get(i).insertChild(nameComment, 0);
}