General discussion

Locked

XML parsing Xerces

By elnaaz ·
I am in a rush to do a project in java , I am not much familiar with parsing xml files but I have to do this , I wonder if I should use SAX or DOM ?! which is better and simpler ?!

and as well I wonder if any one is familiar with xerces 2-7-1 ?!

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by dheerajsingh9 In reply to XML parsing Xerces

It's better you use JDOM, It has all the feature for parsing an xml file.

Collapse -

by kkurnia In reply to XML parsing Xerces

The answer to your problem will be largely depends on what you want to do.

SAX parses XML document in parts, while DOM loads the whole XML document and parse it into hierarchical format in the memory.

In general, you won't do SAX if the XML file is big and complicated.

Follow this link for the article and get more understanding about SAX and DOM:
http://www.code101.com/Code101/DisplayArticle.aspx?cid=37

Xerces ? http://xml.apache.org/xerces2-j/
You should be able to follow the doco there.

Collapse -

by Tanya.Jenkin In reply to XML parsing Xerces

Using JDOM will certainly make things simpler for you. However you'll still need to choose between the DOM & SAX paradigm, and prob pick a parser (e.g. xerces) or use the default one (e.g. JAXP, depending on your system).

Which is better depends on the size/complexity of the xml, the number of accesses to any particular xml doc & your memory constraints.

See http://www.ibiblio.org/xml/books/xmljava/ for lots of good examples, incl a chapter on JDOM, also http://www.jdom.org/ and http://xml.apache.org/xerces2-j/ in addition to the links on prev answers.

Collapse -

by fafafooey In reply to XML parsing Xerces

How large are the files?

IMHO, DOM is easier to use, but if the XML file is very large SAX is better. DOM has to load the entire XML file into memory and SAX doesn't.

Note: My experience with XML is not with Java, so I don't know if the above is true in your case, but it was in mine.

Collapse -

by Ashraf Galal In reply to XML parsing Xerces

SAX notifies the registered document handler whenever an element beings and ends.
This allows the handle to react to the content a piece at a time. so it can build objects or perform any required actions.
Writing application using SAX can be somewhat tedious however because each event must be caught, identified and processed. This is especially painful when the processing depends on where the element occurs in the three.
DOM builds on top of SAX parser.
DOM builds a tree structure from the document.
Once the entire document has been pared, this tree structure can be navigated and explored at length.
Also, an application can modify the DOM tree and save it as a new XML document.
So, for many application the DOM parser is the clear choice.
The entire document is parsed and held in memory before the tree of elements is returned to the application.

SAX is very efficient and fast because it does no store the XML document in memory. It must fit in a system with memory constraints like hand held devices.
Also for applications that need to perform some actions based on the value of certain elements of XML.
If application needs to keep track of the data and their locations. SAX is not a good fit.
DOM is used when application requires the knowledge of the structure of the original XML document or need not map them to internal data objects.
In the contrast, DOM is very memory intensive. Its wasteful when we need to map data to internal data objects.

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums