XML DOM Model
A DOM document is a collection of nodes or pieces of information, organized in a hierarchy.
XML DOM Structure
Everything in an XML document is a node and even the document itself is a node.
Some types of nodes can have children nodes of various types, and others are leaf nodes that cannot have anything under them in the document structure.
The following table shows the various types of nodes and for each the possible child nodes:
Node | Child nodes |
---|---|
Document | Element (maximum of one), ProcessingInstruction , Comment , DocumentType (maximum of one) |
DocumentFragment | Element , ProcessingInstruction , Comment , Text , CDATASection , EntityReference |
EntityReference | Element , ProcessingInstruction , Comment , Text , CDATASection , EntityReference |
Element | Element , Text , Comment , ProcessingInstruction , CDATASection , EntityReference |
Attr | Text , EntityReference |
ProcessingInstruction | No children |
Comment | No children |
Text | No children |
CDATASection | No children |
Entity | Element , ProcessingInstruction , Comment , Text , CDATASection , EntityReference |
Notation | No children |
Example
<?xml version = "1.0"?>
<Company>
<Employee category="technical">
<FirstName>Tom</FirstName>
<LastName>Nolan</LastName>
<ContactNo>1234567890</ContactNo>
</Employee>
<Employee category="support">
<FirstName>Ryan</FirstName>
<LastName>Reynolds</LastName>
<ContactNo>1123456789</ContactNo>
</Employee>
</Company>
note
Learn more about Nodes in XML DOM Nodes chapter.