cancel
Showing results for 
Search instead for 
Did you mean: 

About SAX Parsing and DOM Parsing

former_member207019
Participant
0 Kudos

Hello,

If we want to do java mapping we need to know about DOM and SAX parsing techniques. So could you give me documentaion regarding these two kinds of parsing techniques?

And what is the difference between the SAX and DOM parsing techniques? When do we go for SAX and When do we go for DOM?

Could you give few scenario situations that is necessary to go java mapping?

Thank you

Edited by: jyotsna dm on Apr 15, 2008 10:18 AM

Accepted Solutions (1)

Accepted Solutions (1)

former_member556603
Active Contributor
0 Kudos

HI Jyotsna,

Useful information to you..

Different Types of XML Parsers

In this section, we will give a brief introduction to three of the parsers most widely used in Java programs, namely:

DOM

SAX

JAXB

DOM

DOM (Document Object Model) is an API for HTML and XML documents. It performs two tasks:

It provides the structural representation of the document, i.e. it gives a parsed output of the XML or the HTML document;

It defines the way a structure is to be accessed, meaning it provides a set of interfaces in conformance with the W3C DOM standard.

To explain the process in detail, the DOM XML parser performs text processing of the XML document; it expands all the entities used in the file and compares the structure of the information in the XML document to the related DTD. Then the next step is the creation of the object tree representation of the XML file.

Then the user can access and modify the information in the object using the interfaces provided by DOM. It allows hierarchical access to the information in an XML document.

SAX

Unlike DOM, which provides a default object model, the SAX (Simple API for XML) parser reads in the XML document and fires events based on the things it encounters in the XML document. For example, the event could be the “close” element tags encountered in the XML document.

The steps to SAX are:

Create a custom Java object model for the data.

Create a SAX document handler to create instances of the custom object models from the information stored in the XML document.

Use a SAX parser to create instances of custom object model based on the data stored in the XML documents.

In effect, the SAX API acts like a serial I/O stream. You see the data as it streams in, but you can't go back to an earlier position or leap ahead to a different position. In general, it works well when you simply want to read data and have the application act on it.

JAXB

The Java Architecture for XML Binding (JAXB) is a Java technology that facilitates generation of Java classes from XML schemas. It provides methods to unmarshal XML documents into Java content trees and marshal them back into XML documents.

The most attractive part of JAXB is that its usage does not demand any knowledge of XML. We shall learn more about it in the following section.

http://www.oracle.com/technology/oramag/oracle/03-sep/o53devxml.html

Message mapping internally generates DOM parser.

Java Mapping in XI

https://www.sdn.sap.com/irj/sdn/advancedsearch?cat=sdn_all&query=java+mapping&adv=false&sortby=cm_rn...

SAP Network Blog: Implementing a Java Mapping in SAP PI

/people/carlosivan.prietorubio/blog/2007/12/21/implementing-a-java-mapping-in-sap-pi

Java Mapping (SAP Library - Partner Connectivity Kit)

http://help.sap.com/saphelp_nw04/helpdata/en/e2/e13fcd80fe47768df001a558ed10b6/frameset.htm

SAP Network Blog: XI Java Mapping Helper (DOM)

/people/alessandro.guarneri/blog/2007/03/25/xi-java-mapping-helper-dom

SAP Network Blog: Testing and Debugging Java Mapping

/people/stefan.grube/blog/2006/10/23/testing-and-debugging-java-mapping-in-developer-studio

Binary Conversion in XI - Java Mapping - Code Gallery - Wiki

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/binary%2bconversion%2bin%2bxi%2b-%2bjava...

SAP Network Blog: "JAVA MAPPING", an alternate way of reading a CSV file

/people/rahul.nawale2/blog/2006/07/18/java-mapping-an-alternate-way-of-reading-a-csv-file

Thanks,

Satya Kumar.

Reward points ifn it is useful

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Jyotsna,

1) SAX is a serial parser. It parses the document serially.

DOM creates the the complete XML document in the form of tree in memory.

2) Since SAX parses serially, it brings only a portion of XML document in memory.

DOM creates the complete structure in Memory. So, it consumes much more memory than SAX.

3) SAX is event based, it generates events whenever it gets a node. But DOM is not.

4) You can modify existing XML document using DOM

using SAX, only you can read and generate events but you cannot modify.

5) Once the complete document is in memory using DOM, you can directly go to any node of the document.

Using SAX, you can only serially(starting from first) go to the desired node.

Go to this thread

Hope this helps.

Regards,

Piyush

former_member556603
Active Contributor
0 Kudos

Jyotsna,

Some more information...

http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/package-summary.html

http://java.sun.com/j2se/1.4.2/docs/api/org/w3c/dom/Document.html

http://java.sun.com/j2se/1.4.2/docs/api/org/w3c/dom/package-frame.html

/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i

/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii

/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-iii

Java Mapping-DOM and SAX:

/people/thorsten.nordholmsbirk/blog/2006/08/10/using-jaxp-to-both-parse-and-emit-xml-in-xi-java-mapping-programs

/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i

/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii

/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-iii

http://www.javacommerce.com/displaypage.jsp?name=index.sql&id=18232

http://www.javacommerce.com/displaypage.jsp?name=saxparser1.sql&id=18232

Thanks,

Satya Kumar