I need to read smallish (few MB at the most, UTF-8 encoded) XML files, rummage around looking at various elements and attributes, perhaps modify a few and write the XML back out again to disk (preferably with nice, indented formatting).
What would be the best XML parser for my needs? There are lots to choose from. Some I'm aware of are:
And of course the one in the JDK (I'm using Java 6). I'm familiar with Xerces but find it clunky.
Recommendations?
In addition to SAX and DOM there is STaX parsing available using XMLStreamReader which is an xml pull parser.
If you care less about performance, I'm a big fan of Apache Digester, since it essentially lets you map directly from XML to Java Beans.
Otherwise, you have to first parse, and then construct your objects.