This will help you to get the basic concepts in parsing and how does DOM API differ from SAX.

and non validating parsers-46and non validating parsers-48

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.

Note that when processing invalid documents with a non-validating processor the application may not be presented with consistent information.

For example, several requirements for uniqueness within the document may not be met, including more than one element with the same id, duplicate declarations of elements or notations with the same name, etc.

In these cases the behavior of the parser with respect to reporting such information to the application is undefined. The first step we should do is to learn how to parse and print a simple XML document using both DOM and SAX.Conforming XML processors fall into two classes: validating and non- validating.Validating and non-validating processors alike MUST report violations of this specification's well-formedness constraints in the content of the document entity and any other parsed entities that they read.Non-validating processors are REQUIRED to check only the document entity, including the entire internal DTD subset, for well-formedness.[Definition: While they are not required to check the document for validity, they are REQUIRED to process all the declarations they read in the internal DTD subset and in any parameter entity that they read, up to the first reference to a parameter entity that they do not read; that is to say, they MUST use the information in those declarations to normalize attribute values, include the replacement text of internal entities, and supply default attribute values.] Except when standalone="yes", they MUST NOT process entity declarations or attribute-list declarations encountered after a reference to a parameter entity that is not read, since the entity may have contained overriding declarations; when standalone="yes", processors MUST process these declarations.