TASK : I have an existing xml document (UTF-8) which uses xml namespaces and xml schema. I need to parse to a particular element, append content (that also needs to use xml namespace prefixes) to this element and then write out the Document again.
which is the best XML parser library that I should be using for this TASK ?
I've seen a previous thread (Best XML parser for Java) but was not sure if dom4j or JDOM is any good for namespaces/xmlSchema and good support for UTF-8 characters.
Some parsers that seems like a task for
JDom
Dom4J
XOM
WoodStock
Any idea which one is the best ? 🙂 I use JDK 6 and would prefer NOT to use the built-in SAX/DOM facilities to do this job because that requires me to write too much code.
Would help to have some examples of doing such a task.
Best Answer
Using JDOM, taking an InputStream and making it a Document:
At that point, you have the XML in a Java object. Done. Easy.
You can either use the document object and the Java API to just walk through it, or also use XPath, which I find easier (once I learned it).
Build an XPath object, which takes a bit:
Then just use it, which (thankfully) doesn't take much time at all: