GeeCON Prague 2014*
The moose likes XML and Related Technologies and the fly likes Efficient XML Parsing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Efficient XML Parsing" Watch "Efficient XML Parsing" New topic
Author

Efficient XML Parsing

Paul Michael
Ranch Hand

Joined: Jul 02, 2001
Posts: 697
Hi,

I would like to ask you ranchers how you perform optimized XML parsing.
I'm trying parse a 1KB xml file using DOM and would like to know if my approach is acceptable for a somehow performance critical application.

Let me know if you would rather use SAX and why on these scenarios.



There are also cases in the same class when I had to mix in xpath queries for more complex nested nodes.



Since I'm relatively new to XML parsing, I would love to hear your thoughts on this.

Thank you very much!


SCJP 1.2 (89%), SCWCD 1.3 (94%), IBM 486 (90%), SCJA Beta (96%), SCEA (91% / 77%), SCEA 5 P1 (77%), SCBCD 5 (85%)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Well, almost none of the code you posted has anything to do with actual XML parsing. Except for three lines, it's all code that you would use AFTER the parser has run and produced a DOM.

SAX or DOM? Well, the first thing you need to know there is that the DOM parser calls the SAX parser and uses its output to build the DOM. So if you don't need to use DOM-type access and you can use SAX-type access, then the latter will be a bit faster. However a 1KB XML file is tiny, so it is going to make essentially no difference. Write the program whichever way it's easier to write. Don't write some convoluted code on the theory that it's going to be faster than the natural code, because it probably won't be.

Edit: And if XPath would be the natural way to access the data, then using SAX is going to be horribly complicated. Just use the DOM.
[ August 29, 2006: Message edited by: Paul Clapham ]
Paul Michael
Ranch Hand

Joined: Jul 02, 2001
Posts: 697
Well said. Many thanks Paul.

Keep those suggestions coming! ;)
 
GeeCON Prague 2014
 
subject: Efficient XML Parsing