Java Mapping concepts Understanding

Mapping is the way of transforming one XMLdocument from beginning to end. Those events
structure to another XML Structure. As a part ofare passed to event handlers, which provide
it we do certain operations like breaking childaccess to the contents of the document.
nodes and attaching them to its parent node andEvent Handlers
more in an XML structure.There are three types of event handlers: DTD
In XI/PI we have the following mappingHandlers, for accessing the contents of XML
techniquesDocument-Type Definitions; Error Handlers, for
1. Graphical Mappinglow-level access to parsing errors; and, by far the
2. ABAP Mappingmost often used, Document Handlers, for
3. JAVA Mapping andaccessing the contents of the document. A SAX
4. XSLT Mapping.processor will pass the following events to a
Among all the above mapping techniques, JAVADocument Handler:
mappings improve the performance and are- The start of the document.
preferred as they get executed on J2EE engine- A processing instruction element.
directly. But in case of graphical mapping, XI/PI- A comment element.
converts the mapping program into executable- The beginning of an element, including that
Java code internally based on graphical design andelement’s attributes.
executes it on J2EE engine making it- The text contained within an element.
comparatively less efficiency. Java mappings are- The end of an element.
more useful when performance of integration- The end of the document.
server is concerned during runtime. Java mappingsAdvantages and Disadvantages SAX
are Parsing Programs that can be developed inAdvantages:
NWDS (NetWeaver Developer Studio), import asDOM
.jar files and can be used in the mapping part ofAdvantages:
Integration Repository. NWDS provides suitable1. It is good when random access to widely
Java environment and higher level tools to parseseparated parts of a document is required.
XML documents through the Simple API for XML2. It supports both read and write operations.
(SAX) and the Document Object Model (DOM)>
interfaces. The SAX and DOM parsers areDisadvantage:
standards that are implemented in severalIt is memory inefficient because DOM consumes
different languages. In the Java programmingmore memory to construct the XML tree Object
language, you can instantiate the parsers by usingin the memory corresponding to the input XML its
the Java API for XML Parsing (JAXP).not advisable to use for parsing large XML
JAVA mapping can be done in two ways:documents In that case SAX is preferred over
1. DOM ParsingDOM.
2. SAX Parsing1. It is simple to program.
At the core of the DOM API are the Document2. It is memory efficient as SAX parser does not
and Node interfaces. A Document is a top-levelkeep any of the document tree in memory.
object that represents an XML document. TheDisadvantage:
Document holds the data as a tree of Nodes,The data is broken into pieces and clients never
where a Node is a base type that can be anhave all the information as a whole unless they
element, an attribute, or some other type ofcreate their own data structure.
content. The Document also acts as a factory forDifferences between SAX and DOM parser at a
new Nodes. Nodes represent a single piece ofglance
data in the tree, and provide all of the popularSAX
tree operations. You can query nodes for their1. Parses node by node
parent, their siblings, or their children. You can also2. Doesn’t store the XML in memory
modify the document by adding or removing3. We cant insert or delete a node
Nodes.4. Top to bottom traversing
SAX PARSING TECHNIQUEDOM
SAX (Simple API for XML) is an event-driven1. Stores the entire XML document into memory
model for processing XML. The SAX model isbefore processing
quite different. Rather than building a complete2. Occupies more memory
representation of the document, a SAX parser3. We can insert or delete nodes4. Traverse in
fires off a series of events as it reads theany direction.