• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Efficient XML Parsing

 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 28328
96
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well said. Many thanks Paul.

Keep those suggestions coming! ;)
 
Arthur, where are your pants? Check under this tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic