This tutorial is complete guide
to DOM processing.
What is DOM?
Document Object Model: DOM is a platform- and language-neutral interface,
that provides a standard model of how the objects in an XML object are put
together, and a standard interface for accessing and manipulating these objects
and their inter-relationships.
The DOM is an interface that exposes an XML document as a tree structure
comprised of nodes. The DOM allows you to programmatically navigate the tree and
add, change and delete any of its elements.
The DOM programming interface standards are defined by the
World Wide Web Consortium (W3C).
The W3C site provides a comprehensive reference of the XML DOM.
Getting The XML Root
Element After reading this section, you will be able to retrieve a root
element from the XML document. The JAXP (Java APIs for
XML Processing) provides a common interface for creating and using
xml files using the standard SAX, DOM and XSLTs.
To Count XML
Element In this section, you will learn to count the elements present in a
XML file using DOM APIs.
To Count The Elements
in a XML File In this section, you will learn to count the element in XML
document using DOM APIs defined in the org.apache.xerces.parsers.DOMParser
XML Well-Formed-ness In this section, you will learn to check the
well-formed-ness of a XML
using the DOM interface. A well-formed XML document must
follow the xml syntax rules.
XML Error checker and
locater (DOM) In this section, you will learn to check and locate (line and column number)
an error in your XML document using the DOM APIs. The XML
document follows some rules to check its syntax.
Getting all XML Elements
In this section, you will learn to retrieve all elements of the XML file
using the DOM APIs. This APIs provides some constructors and methods
which helps us to parse the XML file and retrieve all elements.
Getting Dom Tree
Elements and their Corresponding XML Fragments In this section, you will learn to get the elements of a DOM tree and
their corresponding XML fragments. Each element of dom tree
has a node level starting with '0'. Here the DOM tree elements and their
corresponding XML fragments are displayed on the console.
Cloning a XML Element In this section, you will learn to create a clone ofa element
in the DOM tree. In general, the cloning means to create a duplicate.
Remove Element from XML
Document In this section, you will learn to remove any element from a given XML
document. Whenever you remove the xml element from the xml document the data are
also lost from the xml element.
Getting Data from XML File
(Document) In this section, you will learn to retrieve the data from a XML file.
All xml files store the data. You can add and modify the data in the xml
document using the DOM APIs.
XML Validate DTD
In this section, you will learn to validate a xml file against a DTD
(Document Type Definition) using the DOM APIs. A DTD defines
the document structure with a list of legal elements and attributes.
Accessing XML file from Java In this example we have provided you a simple java example with the source
code that will make it possible to access the XML file through Java. For that we have used DOM parser.