File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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

Joined: Mar 22, 2000
Posts: 13036
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.
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
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]
I agree. Here's the link:
subject: SAX or DOM to read XML
It's not a secret anymore!