Full details of XML with suitable example

What is XML

  1. XML (Extensible Markup Language) is a markup language designed to store and transport data in a structured and human-readable way.
  2. It is developed by the W3C (World Wide Web Consortium) and is widely used for data interchange between systems, especially on the internet.
  3. XML is not a programming language. It is a data representation language.
  4. A better method is to follow a standard common data exchange formate which is XML.
  5. All the organization can develop a program which is capable of feching data from their respective database and passing the data like- XML document.
  6. 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.
  7. XML deals with description of data.
  8. 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:

  1. Store data in a platform-independent format.
  2. Share data between different systems and applications.
  3. Separate data from HTML, which focuses on presentation.
  4. Enable data exchange between different software systems like Java, PHP, Python, etc.

 

 Features of XML

  1. Self-descriptive structure:

The tags describe the data themselves.

Example: `<studentName>Rahul</studentName>`

 

  1. User-defined tags:

Unlike HTML, XML tags are not predefined. You can create your own tags.

 

  1. Data transport format:

XML is used to transfer data between applications and platforms.

 

  1. Hierarchical structure:

Data is stored in a tree-like format (root element → child elements).

 

  1. Platform independent:

Works on any system, operating system, or network.

 

  1. Supports Unicode:

It can handle different human languages.

 

  1. 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:

  1. XML Declaration
  2. Root Element
  3. Child Elements
  4. Attributes
  5. 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

  1. XML documents must have a root element

<data> … </data>

 

  1. All tags must be properly closed

<name>Lav Pratap</name>

 

  1. XML is case-sensitive

<Name> ≠ <name>

 

  1. Tags must be properly nested

<student><name>Rahul</name></student>  (Correct)

<student><name>Rahul</student></name>  (Incorrect)

 

  1. Attribute values must be quoted

<student id=”101″> … </student>

 

  1. 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

  1. Simple and easy to understand.
  2. Platform and language independent.
  3. Facilitates data sharing between applications.
  4. Self-descriptive and extensible.
  5. Supports validation using DTD or XML Schema.
  6. Easy to parse using tools or programming languages.

 

Disadvantages of XML

  1. Verbose (large file size).
  2. Difficult to read for large documents.
  3. Slower parsing compared to JSON.
  4. 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

  1. Web services (SOAP, REST APIs)
  2. Configuration files (like AndroidManifest.xml)
  3. Data storage and exchange
  4. RSS feeds and website sitemaps
  5. Office document formats (DOCX, XLSX, etc., use XML internally)

 

Summary

  1. XML stands for Extensible Markup Language.
  2. It is used to store and share structured data.
  3. It allows custom tags to describe data.
  4. XML must be well-formed and follow proper syntax rules.
  5. It is widely used for data interchange, configuration, and APIs.