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.
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 ]