Full details of XML with suitable example
What is XML
- XML (Extensible Markup Language) is a markup language designed to store and transport data in a structured and human-readable way.
- It is developed by the W3C (World Wide Web Consortium) and is widely used for data interchange between systems, especially on the internet.
- XML is not a programming language. It is a data representation language.
- A better method is to follow a standard common data exchange formate which is XML.
- All the organization can develop a program which is capable of feching data from their respective database and passing the data like- XML document.
- At the other end the application data which received data must implement program capable of receiving data from the XML document and storing them into the respective database.
- XML deals with description of data.
- XML uses web services (different type of protocol).
Full Form of XML
XML → Extensible Markup Language
- Extensible: It means that users can create their own tags.
- Markup: It means XML uses tags (like `<name>`, `<age>`) to mark up data.
- Language: It defines a set of rules for structuring data.
Purpose of XML
XML was designed to:
- Store data in a platform-independent format.
- Share data between different systems and applications.
- Separate data from HTML, which focuses on presentation.
- Enable data exchange between different software systems like Java, PHP, Python, etc.
Features of XML
-
Self-descriptive structure:
The tags describe the data themselves.
Example: `<studentName>Rahul</studentName>`
-
User-defined tags:
Unlike HTML, XML tags are not predefined. You can create your own tags.
-
Data transport format:
XML is used to transfer data between applications and platforms.
-
Hierarchical structure:
Data is stored in a tree-like format (root element → child elements).
-
Platform independent:
Works on any system, operating system, or network.
-
Supports Unicode:
It can handle different human languages.
-
Plain text format:
Data is stored in simple text files, easily readable and editable.
Basic Structure of XML Document
An XML document is made up of:
- XML Declaration
- Root Element
- Child Elements
- Attributes
- Comments
Example of XML Document
<?xml version=”1.0″ ?>
<students>
<student id=”11″>
<name>LAV PRATAP</name>
<age>25</age>
<course>MCA</course>
</student>
<student id=”21″>
<name>KARTIK</name>
<age>22</age>
<course6MCA</course>
</student>
</students>
Explanation of Example
| Part | Description |
|---|---|
<?xml version="1.0" encoding="UTF-8"?> |
XML declaration – defines version and character encoding. |
<students> |
Root element – wraps the entire XML data. |
<student> |
Child element – represents one student record. |
id="1" |
Attribute – provides additional information about an element. |
<name>Rahul Sharma</name> |
Element with data. |
</students> |
Closing tag of root element. |
XML Syntax Rules
-
XML documents must have a root element
<data> … </data>
-
All tags must be properly closed
<name>Lav Pratap</name>
-
XML is case-sensitive
<Name> ≠ <name>
-
Tags must be properly nested
<student><name>Rahul</name></student> (Correct)
<student><name>Rahul</student></name> (Incorrect)
-
Attribute values must be quoted
<student id=”101″> … </student>
-
XML documents must be well-formed
It means all syntax rules must be followed.
Example: XML for a Library
<?xml version=”1.0″ encoding=”UTF-8″?>
<library>
<book id=”111″>
<title>Learn HTML, CSS & XML</title>
<author>Lav Pratap</author>
<price>300</price>
</book>
<book id=”112″>
<title>Mastering XML & JAVASCRIPT</title>
<author>KARTIKA</author>
<price>400</price>
</book>
</library>
XML with Attributes Example
<?xml version=”1.0″?>
<employee id=”E011″ department=”IT & ADMIN”>
<name>Ravi Kumar</name>
<designation>Software Engineer</designation>
<salary>50000</salary>
</employee>
Advantages of XML
- Simple and easy to understand.
- Platform and language independent.
- Facilitates data sharing between applications.
- Self-descriptive and extensible.
- Supports validation using DTD or XML Schema.
- Easy to parse using tools or programming languages.
Disadvantages of XML
- Verbose (large file size).
- Difficult to read for large documents.
- Slower parsing compared to JSON.
- Not suitable for real-time web APIs (JSON is preferred today).
Difference Between XML and HTML
| Feature | XML | HTML |
|---|---|---|
| Purpose | Store and transport data | Display data |
| Tag Definition | User-defined tags | Predefined tags |
| Case Sensitivity | Case-sensitive | Not case-sensitive |
| Structure | Data-centric | Presentation-centric |
| Closing Tags | Mandatory | Sometimes optional |
| Example | <name>Lav</name> |
<b>Lav</b> |
Uses of XML
- Web services (SOAP, REST APIs)
- Configuration files (like AndroidManifest.xml)
- Data storage and exchange
- RSS feeds and website sitemaps
- Office document formats (DOCX, XLSX, etc., use XML internally)
Summary
- XML stands for Extensible Markup Language.
- It is used to store and share structured data.
- It allows custom tags to describe data.
- XML must be well-formed and follow proper syntax rules.
- It is widely used for data interchange, configuration, and APIs.

