Slashdot Mirror


Which XML Parser Do You Recommend?

tshieh asks: "I'm trying to add XML-configurability to a Java application, and I'm trying to figure out which XML parser I should use. Any thoughts on whether I would be better off using Xerces, expat, XML4J, or JDOM (or any others)? So far, I've decided to use DOM rather than SAX since I've heard that DOM is easier to use and I don't anticipate my configuration file becoming so large that the slower and more memory-intensive DOM parsing becomes an issue."

4 of 17 comments (clear)

  1. SAX or DOM by geophile · · Score: 4
    I've been using Xerces and have had no problems with it. Haven't tried the others.

    SAX is really simple to use. You write event handlers, where an event is something like "start of document", "end of foobar tag", etc.

    If you can write your application using the SAX event model, then you'd find DOM too complex. DOM is good when you need the entire document as a tree structure, e.g. to do some analysis.

    If you use SAX, and you find yourself writing a lot of code to remember what you've seen, then you should probably consider DOM. If you can look at each tag or data item once and then forget about it, SAX is the way to go.

  2. Xerces by Simon+Brooke · · Score: 3

    Says it all. I've used them all, and in My experience Xerces is relaible, as fast as any, and has the right license.

    --
    I'm old enough to remember when discussions on Slashdot were well informed.
  3. JDOM by bnenning · · Score: 4
    You might want to check out JDOM. It uses the parser of your choice to build a tree structure like DOM, but it has a much simpler API. From their mission page:
    There is no compelling reason for a Java API to manipulate XML to be complex, tricky, unintuitive, or a pain in the neck. JDOM is both Java-centric and Java-optimized. It behaves like Java, it uses Java collections, it is completely natural API for current Java developers, and it provides a low-cost entry point for using XML.

    We've been using it at work and are happy with it so far.

    --
    How to solve most of our problems: 1.Lots of nuclear plants. 2.Cure aging.
  4. DOM sucks by ikekrull · · Score: 3

    Personally, i find SAX easier to use than DOM..

    It also takes a whole lot less memory and time to parse than the DOM approach.

    We process XML files that can be up to 10MB in size, and DOM parsing these files brings my 500MHz P3 to its knees (yes i have increased the JVM heap size)

    Parsing with SAX, however, has proved simple, clean and easy with no performance problems at all.

    If youre definitely wanting to use the DOM, try NanoXML.. its much smaller that Xerces and the like, and is perfect for parsing config files etc., as will as being small enough (6KB or so) for client-side and embedded use.

    However, for an all-round, no compromise XML parsing solution, then Xerces is pretty good.

    --
    I gots ta ding a ding dang my dang a long ling long