cancel
Showing results for 
Search instead for 
Did you mean: 

Reg: Parsers

Former Member
0 Kudos

Hi,

Can you provide me the links to find the differences and uses in DOM and SAX parsers.

regards,

sri

Accepted Solutions (0)

Answers (5)

Answers (5)

former_member556603
Active Contributor
0 Kudos

Hi Srikanth,

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 if it si useful..

Former Member
0 Kudos

Hi Srikanth,

Don't know the links, but can tell you some differences.

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 genrates 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.

Hope this helps.

Regards,

Piyush

aashish_sinha
Active Contributor
0 Kudos

Hi,

DOM and SAX Parser

The DOM parser always reads the whole xml document as an atomar processing step. It either throws an exception when it encounters an error during parsing, or returns a complete DOM tree as a representation

of the xml document.

In contrast, the SAX parser works incrementally and generates events that are passed to the application. An application can receive these events by implementing the abstract methods of the SAX2XMLReader class.

What are the pros and cons?

The DOM parser offers a convenient way for reading, analizing, manipulating and writing back XML files. Since it always reads the whole file, before further processing can take place, using the DOM parser may lead to difficulties when processing huge XML files.

The SAX parser, on the other hand, does not generate a data representation of the XML content, so there is some more programming required, compared to the DOM parser. However, if demanded by the

application, the SAX parser enables stream-processing and partial processing of XML sources, which both cannot be done by the DOM parser.

As a rule of thumb, which parser class to use, the following can be checked:

Whenever you need stream-processing or partial processing of XML files, you need the SAX parser.

Whenever you need a complete representation of the XML content, you should prefer the DOM parser.

Still no decision? Then try the DOM parser first, since it is more convenient than the SAX parser.

Refer these links

http://xerces.apache.org/xerces-c/apiDocs/classSAX2XMLReader.html

http://xerces.apache.org/xerces-c/apiDocs/classDOMBuilder.html

Regards

Aashish Sinha

PS : reward points if helpful

Former Member
0 Kudos

Hi

http://www.sdc.iup.edu/outreach/fall2000/xml2/domvssax.html

This give u clear diff

Ps: If helful reward points

Former Member
0 Kudos

Hi

http://www.sdc.iup.edu/outreach/fall2000/xml2/domvssax.html

For SAX and DOM

http://java.sun.com/webservices/docs/1.1/tutorial/doc/

Advantages of using XSLT mapping

1.)XSLT program itself defines its own target structure.

XSLT programs can be imported into SAP XI. Message mapping step can be avoided. One can directly go for interface mapping once message interfaces are created and mapping is imported.

XSLT provides use of number of standard XPath functions that can replaces graphical mapping involving user defined java functions easily.

File content conversion at receiver side can be avoided in case of text or html output.

Multiple occurrences of node within tree (source XML) can be handled easily.

XSLT can be used in combination with graphical mapping.

Multi-mapping is also possible using xslt.

XSLT can be used with ABAP and JAVA Extensions.

Disadvantages of using XSLT mapping

1. Resultant XML payload can not be viewed in SXMB_MONI if not in XML format (for service packs < SP14).

Interface mapping testing does not show proper error description. So errors in XSLT programs are difficult to trace in XI but can be easily identified outside XI using browser.

XSLT mapping requires more memory than mapping classes generated in Java.

XSLT program become lengthier as source structure fields grows in numbers.

XSLT program sometimes become complex to meet desired functionality.

Some XSL functions are dependent on version of browser.

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/abap/xmlXSLTwith+ABAP&

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/xi/mapping+techniques&;

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/xsltsampletoencode%2CdecodeXMLfile&

XML Tutorail

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

Using SAX Parser in Java Program

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

DOM Parser

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

DOM PARSER API

________________________________________

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

DOM

o

&#61607;

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

tutorial sax and dom

For a tutorial on the methods of SAX and DOM http://java.sun.com/webservices/docs/1.1/tutorial/doc/

A very important place where you will use JAVA in XI is while doing your Mapping.

There will be cases when JAVA MAPPING is the best solution to go for.

There are 2 types of Parsers available for JAVA Mapping. DOM Parser and SAX parser. Just got through the following links to understand more on Java Mapping and the APIs available.

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

XSLT Mapping:

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/01a57f0b-0501-0010-3ca9-d2ea3bb9...

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/9692eb84-0601-0010-5ca0-923b4fb8...

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/006aa890-0201-0010-1eb1-afc5cbae...

/people/sap.user72/blog/2005/03/15/using-xslt-mapping-in-a-ccbpm-scenario

/people/anish.abraham2/blog/2005/12/22/file-to-multiple-idocs-xslt-mapping

Message Mapping:

http://help.sap.com/saphelp_nw04/helpdata/en/43/c4cdfc334824478090739c04c4a249/content.htm

/people/sravya.talanki2/blog/2005/08/16/message-mapping-simplified--part-i

/people/sravya.talanki2/blog/2005/12/08/message-mapping-simplified-150-part-ii

/people/stefan.grube/blog/2005/12/29/new-functions-in-the-graphical-mapping-tool-xi-30-sp13

Thanks Regards

Anil