Differentiate between validating and non validating xml parser
To keep the example simple this program generates a XML file from a Vector preloaded with hard coded data.
As a part of it we do certain operations like breaking child nodes and attaching them to its parent node and more in an XML structure. Java mappings are more useful when performance of integration server is concerned during runtime.In XI/PI we have the following mapping techniques 1. Java mappings are Parsing Programs that can be developed in NWDS (Net Weaver Developer Studio), import as files and make use of in the mapping part of Integration Repository. Among all the above mapping techniques JAVA mappings improves the performance and are preferred as they gets executed on J2ee engine directly.NWDS provides suitable Java environment and higher level tools to parse XML documents through the Simple API for XML (SAX) and the Document Object Model (DOM) interfaces. The first step we should do is to learn how to parse and print a simple XML document using both DOM and SAX.This will help you to get the basic concepts in parsing and how does DOM API differ from SAX.
6.1.1 Using DOM parses a XML file and prints it on the console . This is a two stage process, first it parses the XML file and creates a tree structure in the memory.
The next stage is to traverse the tree and print the contents.
a) Construction of DOM tree b) Traversing the DOM tree It does a Depth First Pre Order Traversal , for more on tree traversal techniques see here As it goes through each node it prints it contents.
This snippet explains how to handle the element Node parses a XML document and prints it on the console.
When a Sax parser parses a XML document and every time it encounters a tag it calls the corresponding tag handler methods when it encounter a Start Tag it calls this method public void start Element(String name, Attribute List attrs) when it encounter a End Tag it calls this method public void end Element(String name) This program also parses a XML file and prints it on the console . In this example, the Print Using Sax Class extends the Handler Base class and implemets the call back methods to handle the printing The steps involved are Get a instance of SAX parser, The previous program illustrated how to Parse an existing XML file using both SAX and DOM Parsers.
But generating a XML file from scratch is a different story , for instance you might like to generate a xml file for the data extracted form the database.