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 adding an attribute to a specific element.
Random random = new Random(); int randNum;
Element ranEle = null;
Attribute attribute = null;
for (int i = 0 ; i < 10 ; i ++) {
randNum = random.nextInt(1729);
//Create a new attribute with boolean string as value
attribute = new Attribute("even", String.valueOf(randNum % 2 == 0));
ranEle = new Element("Number");
ranEle.appendChild(String.valueOf(randNum));
ranEle.addAttribute(attribute); //Add the new attribute
//Append the newly created child element
doc.getRootElement().appendChild(ranEle);
}