Java DOM Tutorial
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.
-
Creating Blank DOM Document
This section shows you how to create the blank DOM document.
-
Adding Child Elements to the DOM tree
This lesson shows you how to create root and child elements in the DOM tree.
- 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 package.
-
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. - Searching an
Element in the given XML Document
In this you will learn to search an element in the specified XML document using DOM APIs defined in the org.apache.xerces.parsers.DOMParser package.
-
Create - XML File (Document)
In this section, you will learn to create a XML document using the DOM APIs. This XML document uses 1.0 version and UTF-8 encoding. -
Regenerating XML file
In this section, you will learn to get the elements and its value using DOM APIs. -
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.
-
Adding DOCTYPE to a
XML File
In this section, you will learn to add a DOCTYPE to your XML file using the DOM APIs.
-
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 of a 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.
-
Storing Data (Retrieved from
a XML Document) to a File
In this section, you will learn to store data (retrieved from the XML document) to a specified file (with extension '.txt', '.doc', '.xls', '.shtml' etc.) in different formats (text, xml, html etc.).
-
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.
XML
Tutorials Links
Links of Many XML Tutorials. Here you will find lots of XML Tutorials.