× back

XML

Features and Advantages of XML

Disadvantages of XML

Is XML Still Recommended in Modern Times?

XML continues to be widely used and recommended in many scenarios, especially for data interchange and structured data storage. However, it is important to consider some of the drawbacks and challenges associated with XML:

Applications of XML

Difference between HTML and XML

XML File and Syntax

An XML (eXtensible Markup Language) file is a text-based format used for storing and transporting structured data. It typically uses the file extension .xml to indicate that it contains XML-formatted data.

The syntax of an XML file follows a set of rules and conventions to define its structure and content. Let's break down the syntax starting with the declaration:

                
<?xml version="1.0" encoding="ISO-8859-1"?>
                
            

In this declaration:

Following the XML declaration, we have the root element, which acts as the container element for all other elements in the XML file:

                
<root>
    <child1>Content of child 1</child1>
    <child2>Content of child 2</child2>
</root>
                
            

In this example:

The syntax of XML is based on using tags to mark up data, with each tag representing an element and its content. Tags must be properly nested, and elements can have attributes for additional information:

                
<person>
    <name>John Doe</name>
    <age>30</age>
    <email>johndoe@example.com</email>
</person>
                
            

In this example:

XML Tree

  • An XML tree is a hierarchical structure used to represent data in XML format.
  • It consists of elements organized in a parent-child relationship, forming a tree-like structure.
  • The top-level element in an XML tree is called the root element, which contains all other elements.
  • Each element can have child elements, attributes, or text content.
  • Elements can be nested within each other, creating a hierarchy that represents the relationships between different parts of the data.
  • Attributes provide additional information about elements, such as metadata or properties.
  • Text content within elements represents the actual data stored in the XML document.
  • XML trees are used to organize and store structured data in a format that is both human-readable and machine-understandable.
  • XML trees can be visualized using tree diagrams or represented in textual form using indentation to show the hierarchy.

Example of an XML Tree:

            
<students>
    <student>
        <name>John Doe</name>
        <email>johndoe@example.com</email>
        <age>25</age>
    </student>
    <student>
        <name>Jane Smith</name>
        <email>janesmith@example.com</email>
        <age>22</age>
    </student>
    <student>
        <name>Michael Johnson</name>
        <email>michael@example.com</email>
        <age>28</age>
    </student>
</students>
            
        

Design an XML document that contains email information of 5 students.

                            
<?xml version="1.0" encoding="UTF-8"?>
<students>
    <student>
        <name>John Doe</name>
        <email>john.doe@example.com</email>
    </student>
    <student>
        <name>Jane Smith</name>
        <email>jane.smith@example.com</email>
    </student>
    <student>
        <name>Michael Johnson</name>
        <email>michael.johnson@example.com</email>
    </student>
    <student>
        <name>Emily Brown</name>
        <email>emily.brown@example.com</email>
    </student>
    <student>
        <name>David Wilson</name>
        <email>david.wilson@example.com</email>
    </student>
</students>
                            
                        

XML DTD (Document Type Definition)