DOM Parser Tutorial


 

DOM Parser Tutorial

In this section, we will introduce you to about the DOM api.

In this section, we will introduce you to about the DOM api.

DOM Parser Tutorial

Introduction

Dom stands for Document Object Model. It is a Java API(Application Programming Interface ) for XML Parsing. It is available in package org.w3c.dom.
Dom is a cross-language API. It provides many interface for accessing creating and manipulating a XML document.  It represents XML document in the form of tree, and it also represent relationship between tree elements.
With the help of Dom api, user  can add, delete and traverse XML document nodes. The DOM  are developed  by the World Wide Web Consortium (W3C). It provides different classes and method for parsing.

The org.w3c.dom package contains following interfaces:

Attr

The Attr is an interface. It specifies attributes of an element of XML document. The acceptable values of attributes are specified in DTD(Document type Definition ). But it is not a part of DOM tree. It is like properties of element.

CDATASection

CDATASection is an interface. CDATA section is a part of element content that is like as character data. Text inside this section will be ignored by the parser. It extends Text interface for storing text of CDATASection.

CharacterData

The CharacterData is an interface of DOM. It extends Node interface, which has various properties and  method for accessing character data. It can be implements  through the Comment, Text and CDATASection.

Comment

The Comment interface extends a CharacterData object. It shows all the character of comment. It specifies comment in XML document. <!-- text--> this syntax is used for writing comment .

Document

The Document extends Node object. It describes whole XML document. It is a root node of XML document All nodes must be added inside the Document, because it is a root of XML tree.

DocumentFragment

The DocumentFragment extends Node object. Lightweight version document object can be represented through it. It is very simple for extracting subtree of document..

DocumentType

The DocumentType extends Node object. It represents doctype property of document. value of doctype is either zero or Document type. Document type declaration is compulsory for XML document.

DOMImplementation

It is a inter face of DOM API.  It provides various method, that uses for performing operations. These operations  are independent from any particular instance of document object

Element

The Element extends Node object. It specifies an element in XML document The Element interface provides different attributes. Attributes value may be contains entity references.

Entity

The Entity extends Node object. It specifies entity in XML document. It may be either  parsed or unparsed. It describes a valid storage unit. it does not describe entity reference like &copyright;. 

EntityReference

The EntityReferences is used for representing entity in XML document. It presents in DOM only when an entity present in source document. It can not used for five predefine entity &amp;, &gt;, &apos, &quot.

NamedNodeMap

The NamedNodeMap interface represents a list. like as NodeList. It not maintained in specified order.

Node

The Document Object Model have only a primary datatype that is node interface. It specifies the single node in the document tree. For example, text node have no children, and adding children nodes to text node results a DOMException being raised.
The attributes like nodeValue, nodeName and properties are included as a mechanism to achieve node information without casting down to specific interface.

NodeList

0

NodeList stores the ordered list of children of each node of the DOM Document. This is a indexed list similar to the array in java starting from 0 index and ends with one less than the length of the list.

Notation

The notation Interface specifies the notations defined in DTD(Document Type Definition). The Notation is not the part of the tree, it is the way for accessing the documents notations. The notation is used for the formal declaration of processing instructions. The documents notation is access through the getNotations() method of document type object.

1

ProcessingInstruction

The ProcessingInstruction describes the data found in processing instruction. The ProcessingInstruction interface inherits from Node, and represents an XML processing instruction. for example,
<?xml-stylesheet type="text/xml" href="abc.txt"?>

Text

2

The Text interface represents a text node or textual content (termed character data in XML) of an element and inherits from CharacterData. This can be a child of an element, an attribute, or an entity reference. When a document is first made available via the DOM, there is only one Text node for each block of text.

Ads