The DOM refers to Document Object Model. The DOM parses the XML file, creates the DOM objects and loads it into the memory in the tree structure.
Note: DOM is simple and easy to use but it consume lots of memory and slow.
Interfaces defined by DOM:
The DOM defines several Java interfaces. Here are the most common interfaces:
1. Document: It represents the entire XML document. A Document object is also known as a DOM tree. The getDocumentElement() method of Document interface returns the root element of the document.
2. Node: It represents the base datatype of the DOM.
Commonly used methods of Node interface:
a. Node.getFirstChild(): It returns the first child of the specified node.
b. Node.getLastChild(): It returns the last child of the specified node.
c. Node.getNextSibling(): It returns the next sibling of the specified node.
d. Node.getPreviousSibling(): It returns the previous sibling of the specified node.
e. Node.getAttribute(attrName): It returns the requested attribute value of the specified node.
3. Element: It represents the object.
4. Attr: It represents the attribute of an element.
5. Text: It represents the actual content of an attribute or element.
Java dom xml parser examples:
Next Topic: DOM XML parser to parse XML file in java.
Previous Topic: XML parser overview.