hi, I havent worked much on XML, but I just wanted to clarify this question. If the DOM creates a tree, and one is supposed to travesrse it for getting a specific node, then is it worth while using DOM for say some 15 -20 nodes? I think it will traverse the tree each time a specific nod value is asked for. So request for 20 nodes will traverse the tree 20 times. in comparision, SAX will parse it sequentiually and we can extract the required data while parsing itself. Doesnt this make SAX more effective when we have huge XML??? Please let me know if my thoughts are ambigiious Thnx Rajani
I think it depends on what your doing with the parsed data. If you just need to process it once, say convert it to html, I'm guessing SAX would be more efficient. But if you need to parse the document and keep it in memory for random access, maybe it's better to leave it in the dom rather than map it to some other objects in memory. Unless you think that you can map the dom to your own objects that will be more efficient to access. You can do this but you probably want to weight that effort against your anticapated performance gains. Thanks for reading.
DOM and SAX has their own pro's and cons depending on how they are used. DOM is usefull when data/object represented in XML/XSL file is required for processing more than once. Down side is you can't load whole XML file in to DOM (memory) if XML file size is too large. http://22.214.171.124/developerlife/parsertest2/performance.html has performance statistics for reading XML files with varying sizes using different parsers. SAX is usefull when you need to read data from XML file once, and either convert node data into objects or process immediatly and there is no need to go back to XML file for structural information.