Mark Wilson I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :
10/13/2004
Times viewed :
5121
javax.xml Package Description
This reference provides explanations and descriptions for the javax.xml class
packages.
Parsers
Provides classes allowing the processing of XML documents. Two types of
plugable parsers are supported:
SAX (Simple API for XML)
DOM (Document Object Model)
One of the most important layers
to any xml-aware application is the XML parser. This component handles the
important task of taking a raw xml document as input and making sense of
Document; it will make sure that xml document is well-formed, and if a DTD or
Schema is referred, it may be ensure that document is valid.
What results from an XML
document being parsed is typically a data structure that can be manipulated and
handled by other xml tools or Java APIs. Selecting an xml parser is not an easy
task. There are no hard and fast rules, but two main criteria are used. The
first is the speed of the XML parser and second is the conformity to the xml
specification. As the complexity of the xml document grows in terms of size,
the speed of any xml parser in an important factor. Because performance is
often more of a priority, some parsers may not conform to the finer points of
the xml specification. User must need to decide the balance between these two
factors depending upon the need of your application.
The Simple API for XML (SAX) APIs
To start the process, an
instance of the SAXParserFactory class is used to generate an instance of the
parser. The parser wraps a SAXReader object. When the parser's parse() method
is invoked, the reader invokes one of several callback methods implemented in
the application. Those methods are defined by the interfaces ContentHandler,
ErrorHandler, DTDHandler, and EntityResolver.
The Document Object Model (DOM) APIs
You use the
javax.xml.parsers.DocumentBuilderFactory class to get a DocumentBuilder
instance, and use that to produce a Document (a DOM) that conforms to the DOM
specification. The builder you get, in fact, is determined by the System
property, javax.xml.parsers.DocumentBuilderFactory, which selects the factory
implementation that is used to produce the builder. (The platform's default
value can be overridden from the command line.)
You can also use
the DocumentBuilder newDocument() method to create an empty Document that
implements the org.w3c.dom.Document interface. Alternatively, you can use one
of the builder's parse methods to create a Document from existing XML data. The
result is a DOM tree like that shown in the diagram.
Resources
Here is the list of the
most commonly used XML Parser. This list does not show whether the parser
supports validation or not. No overall ranking is suggested here, but there is
a wealth of information on the web pages of these parser.
All the code examples in this tutorial are based on Sun Microsystems
Crimson and Apache’s Xerces parser. To know more about other parsers, please
visit their website.