aspose file tools*
The moose likes XML and Related Technologies and the fly likes SAX or DOM to read XML 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 "SAX or DOM to read XML" Watch "SAX or DOM to read XML" New topic
Author

SAX or DOM to read XML

John King
Ranch Hand

Joined: Aug 27, 2002
Posts: 165
I need to read a xml string and create an object to
represent the xml. Which one of sax and dom is better?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
If you want an object in memory that represents an XML document, you have to use DOM or a related technology. SAX parsers simply scan once through a document and it is up to the programmer to hang on to the data needed.
Bill
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Here's a simple method for parsing a string into a DOM object. It's up to you from that point forward to create your specific object based on that DOM tree.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
 
wood burning stoves
 
subject: SAX or DOM to read XML