Skip to content
Home » XML Data Model

XML Data Model


XML DATA MODEL

The XML Data Model defines how data is represented, structured, stored, and manipulated using XML (eXtensible Markup Language). Unlike the relational model (tables, tuples, attributes), the XML data model is hierarchical, tree-based, and supports semi-structured data.

An XML document represents data as a tree of nested elements, each with attributes, text, and relationships.
This makes XML ideal for irregular, evolving, and document-centric data.


1. BASIC STRUCTURE OF THE XML DATA MODEL

The XML Data Model consists of:

  1. Elements
  2. Attributes
  3. Text nodes
  4. Comments
  5. Namespaces
  6. Hierarchy (Tree structure)
  7. Document Order
  8. Mixed Content
  9. Schema/DTD structure

Each is discussed below.


2. HIERARCHICAL (TREE) MODEL

XML represents data in a tree structure:

          Root Element
              |
      -------------------
      |                 |
   Element 1         Element 2
      |
   Sub-element

This is called the DOM tree (Document Object Model).
Every XML document must have a single root element.

Example:

<Company>
    <Employee>
        <Name>Amit</Name>
        <Salary>50000</Salary>
    </Employee>
</Company>

3. ELEMENTS (Main building block)

Elements represent data objects in XML.

Syntax:

<ElementName>content</ElementName>

Elements can contain:

  • Other elements (nested)
  • Text
  • Attributes

Example:

<Book>
    <Title>DBMS</Title>
    <Author>Navathe</Author>
</Book>

4. ATTRIBUTES

Attributes store additional properties of elements.

Syntax:

<Element attributeName="value">content</Element>

Example:

<Employee id="101">Amit</Employee>

Attributes are name-value pairs.


5. TEXT NODES

The actual data inside elements is represented as text nodes.

Example:

<Name>John</Name>

Here John is the text node.


6. MIXED CONTENT

XML allows elements to contain both text and child elements.

Example:

<Note>
    Hello <b>World</b> !
</Note>

Useful for documents such as:

  • Articles
  • Blogs
  • Rich-text documents

7. ORDERED NODES

Unlike relational tables, order matters in XML.

Example:

<Name>First</Name>
<Name>Second</Name>

The sequence is important in XML.
This makes XML suitable for ordered data such as:

  • Steps
  • Recipes
  • Dialogs
  • Messages

8. XML ATTRIBUTES vs ELEMENTS

Elements:

  • Store complex hierarchical data
  • Can contain nested elements

Attributes:

  • Store simple metadata
  • Cannot contain child nodes
  • Cannot be nested

9. ID and IDREF (References)

XML supports relationships using IDs.

Example:

<Employee id="E101"/>
<Project assignedTo="E101"/>

This allows relational-like connections.


10. XML NAMESPACES

Namespaces avoid naming conflicts when combining XML documents from different systems.

Syntax:

xmlns:prefix="URI"

Example:

<book xmlns:h="http://html.com">
   <h:title>XML Guide</h:title>
</book>

11. SEMI-STRUCTURED DATA MODEL

XML supports irregular, incomplete, or optional structures.

Example:

<Customer>
    <Name>Aditi</Name>
    <Email>aditi@gmail.com</Email>
    <!-- Address optional -->
</Customer>

Not all records have the same structure, unlike relational tables.


12. XML SCHEMA (XSD) & DTD

The XML Data Model supports two schema definitions:


A. DTD (Document Type Definition)

Defines structure in a simple grammar.

Example:

<!ELEMENT Book (Title, Author)>

B. XML Schema Definition (XSD)

More powerful than DTD.

  • Supports data types
  • Constraints
  • Namespaces

13. XML INFOSET (Information Set)

A formal model that defines:

✔ Nodes
✔ Attributes
✔ Namespace declarations
✔ Document structure

Used internally by XML processors.


14. XML DATA MODEL vs RELATIONAL MODEL

XML Data ModelRelational Data Model
Hierarchical (tree)Tabular (rows/columns)
Schema optionalSchema required
Supports nested elementsNo nesting
Order mattersOrder doesn’t matter
FlexibleRigid
Good for documentsGood for structured data

15. BENEFITS OF XML DATA MODEL

✔ Ideal for hierarchical/semi-structured data
✔ Self-describing format
✔ Platform and language independent
✔ Excellent for data exchange
✔ Supports complex documents
✔ Easily extendable
✔ Supports web services, configuration files, and metadata


EXAMPLE OF XML DATA MODEL (Simple XML Document)

<Student>
    <RollNo>101</RollNo>
    <Name>Ravi</Name>
    <Courses>
         <Course code="CS101">DBMS</Course>
         <Course code="CS102">Java</Course>
    </Courses>
</Student>

This illustrates:

  • Hierarchical structure
  • Child elements
  • Attributes
  • Order
  • Nested lists

Perfect 5–6 Mark Short Answer

The XML Data Model is a hierarchical, tree-based representation of data where information is stored as elements, attributes, and text nodes. Unlike relational databases, XML supports semi-structured data, nested elements, mixed content, and ordered nodes. It uses DOM trees, namespaces, IDs, and XML schema definitions to model complex, flexible documents. The XML Data Model is widely used for data exchange, web applications, configuration files, and document-centric data.