Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Efficient XML Parsing

 
Paul Michael
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Paul Clapham
Sheriff
Posts: 21314
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well said. Many thanks Paul.

Keep those suggestions coming! ;)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic