XML DOM | Model

XML DOM - Model


Hello folks! welcome back to a new section of our tutorial on XML DOM. In this tutorial, we are going to be studying about the XML DOM Model.

Now that we have known what DOM means, let us now discuss about DOM structure. A DOM document is a collection of nodes or pieces of information which is organized in a hierarchy. Some types of nodes may have child nodes of various types and others are leaf nodes that cannot have anything under them in the document structure. Following below is the list of node types, with a list of node types that they may have as children -


  • Document - Element (maximum of one), ProcessingInstruction, Document Type (maximum of one), Comment.
  • Text - No children.
  • Attr - Text, EntityReference.
  • EntityReference - ProcessingInstruction, Element, Comment, Text, EntityReference, CDATASection.
  • DocumentFragment - Element, Comment, ProcessingInstruction, CDATASection, Text, EntityReference.
  • Element - Element, ProcessingInstruction, CDATASection, EntityReference, Comment, Text.
  • ProcessingInstruction - No children.
  • Comment - No children.
  • CDATASection - No children.
  • Entity - ProcessingInstruction, Comment, Element, CDATASection, EntityReference, Text.
  • Notation - No children.


Example

Let us consider the DOM representation of the following XML document node.xml -

<?xml version = "1.0"?>
<Company>
   <Employee category = "technical">
      <FirstName>Kennedy</FirstName>
      <LastName>Nkpara</LastName>
      <ContactNo>1234567890</ContactNo>
   </Employee>
   
   <Employee category = "non-technical">
      <FirstName>Stephanie</FirstName>
      <LastName>Francis</LastName>
      <ContactNo>1234667898</ContactNo>
   </Employee>
</Company>

Flowchart

The Document Object Model of the above XML document would be as follows -

Document Object Model (Flowchart)

From the above flowchart, we can conclude that -

  • Node object can have only one parent node object. This occupies the position above all the nodes.
  • The parent node can have multiple nodes called the child nodes. These child nodes can have additional nodes called attribute nodes. In the above example, we have two attribute nodes which are the Technical and Non-technical. The attribute nodes is not actually a child of the element node, but is still associated with it.
  • These child nodes in turn can also have multiple child nodes. The text within the nodes is called the text nodes.
  • The node objects at the same level are called siblings.
  • The DOM identifies -
    • the objects to represent the interface and manipulate the document.
    • the relationship among the objects and interfaces.


Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about XML DOM Nodes.

Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.