tags:

views:

300

answers:

3

i want to do read simple XML file .i found http://stackoverflow.com/questions/528664/simple-way-to-do-xml-in-java

There are also several parsers available just wanted to make sure that what are the advantages of using XOM parser over suns parser

Any suggestions?

+2  A: 

XOM is extremely quick compared to the standard W3C DOM. If that's your priority, there's none better.

However, it's still a DOM-type API, and so it's not memory efficient. It's not a replacement for SAX or STAX.

skaffman
+2  A: 

How do you need to access your data?

If it is one-pass, then you don't need to build the tree in memory. You can use SAX (fast, simple) or StAX (faster, not quite so simple).

If you need to keep the tree in memory to navigate, XOM or JDOM are good choices. DOM is the Choice Of Last Resort, whether it is level 1, 2, or 3, with or without extensions.

Xerces, which is the parser included with Java (although you should get the updated version from Apache and not use the one bundled with Java, even in 6.0), also has a streaming native interface called XNI.

If you want to hook other pre-made parts up in the chain, often SAX or StAX work well, since they might build their own model in memory. For example, the Saxon XSLT/XQuery engine works with DOM, SAX or StAX, but builds internally a TinyTree (default) or DOM (optional). DataDirect XQuery works with SAX, StAX or DOM also, but really likes StAX.

lavinio
Odd that you say SAX is simpler than StAX. SAX may be a simpler API, but writing StAX-based code is an awful lot easier than writing against SAX.
skaffman
+1  A: 

You might want to check this question about the best XML library and its top (XOM) answer; lots of details about advantages of XOM. (Leave a comment if something is unclear; Peter Štibraný seems to know XOM inside and out.)

As mentioned, XOM is very quick and simple in most tasks compared to standard javax.xml. For examples, see this post in a question about the simplest way to read in an XML file in Java. I collected some nice examples that make XOM look pretty good (and javax.xml rather clumsy) there. :-)

So personally I've come to like XOM after evaluating (as you can see in the linked posts); for any new Java project I'd most likely choose XOM for XML handling. The only shortcoming I've found so far is that it doesn't really support streaming XML directly (unlike dom4j where I'm coming from).

Jonik