We are moved to new domain
Click -> www.ehowtonow.com
Friday, 8 November 2013

JAXP – Java API for XML Processing – DOM Parser


The Java API for XML Processing (JAXP) is for processing XML document using application written in Java programming language.JAXP contains following parsers
  1. SAX  -Simple API for XML Parsing.
  2. DOM - Document Object Model.
  3. XSLT – Extensible Stylesheet Language Transformations
  4. StAX – Streaming API for XML
The SAX and DOM used to parse the xml data as a stream of events or to build an object representation of XML data.The XSLT gives you control over the presentation of the data and enabling you to convert data to other XML document or to other format, such as HTML.JAXP also provides namespace support.
JAXP allow you to use any of XML-compliant parser from within your application, which is called pluggability layer.The  pluggability layer lets you plug in an implementation of the SAX or DOM parser.It also let you to plug in an XSL Processor, which used to control how your data is displayed.

Document Object Model API

dom parser
This image is collected from oracle web site
A DOM is a standard tree structure, where each none contains one of the component from XML structure. There two common types of elements in DOM, which are element node and text node.Using DOM functions you can create, remove, change the content of node and traverse the node hierarchy.

The DOM parser parses an XML document into an Object.The whole document is converted into simple Object which takes lot of memory.

You can use the javax.xml.parsers.DocumentBuilderFactory class to get a DocumentBuilder instance, and you can use that instance to produce a Document object that conforms to the DOM specification.The system property determines builder at run time using javax.xml.parsers.DocumentBuilderFactory, which selects the factory implementation  to produce the builder. The platform's default value can be overridden from the command line.

The DocumentBuilder class newDocument() method used to create an empty Document that implements org.w3c.dom.Document interface. Alternatively you can use the builder’s parse() method to create Document from existing XML data.The result DOM tree will be like that shown in Figure.
Packages in DOM
S.No
Package
Description
1 org.w3c.dom Defines the DOM programming interface for XML
2 javax.xml.parsers Defines the DocuentBuilderFactory class and DocumentBuilder class, which returns an object that implements the W3C Document interface.The factory that is used to create the builder is determined by the javax.xml.parsers system property, which can be set from the command line or overridden when invoking the new Instance method. This package also defines the ParserConfigurationException for reporting errors.

Shop and help us

Flipkart Offer Snapdeal offer Amazon.in offer Amazon.com offer
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

Item Reviewed: JAXP – Java API for XML Processing – DOM Parser Rating: 5 Reviewed By: eHowToNow