Catch Up with Us!

A Gentle Introduction to XML

Introduction

XML (Extensible Markup Language) is a markup language used for storing, structuring, and exchanging data in a machine-readable and human-readable format. It is widely used in enterprise systems, configuration files, document storage, and legacy web services.

Although modern APIs often use JSON, XML remains important in industries such as finance, healthcare, publishing, and government systems.

What Makes XML Special?

Unlike HTML, XML does not have predefined tags. Instead, users define their own tags to describe data meaningfully.

For example, a simple shopping list can be represented as:

<?xml version="1.0" encoding="UTF-8"?> <list>    <item>        <name>Noodles</name>        <qty>3</qty>    </item>    <item>        <name>Sugar</name>        <qty>1lb</qty>    </item> </list>

Key idea:

XML focuses on data structure and meaning, not presentation.

XML vs HTML vs JSON (Modern Context)

Format

Purpose

Usage Today

XML

Data representation

Enterprise systems, SOAP APIs, configs

HTML

Web page structure

Web browsers

JSON

Lightweight data exchange

REST APIs, modern web apps

Modern trend:

  • JSON has largely replaced XML in web APIs
  • XML is still widely used in legacy systems and enterprise integrations

XML Flexibility

XML allows complete flexibility in naming tags:

<item>    <name>Noodles</name>    <quantity>3</quantity> </item>

Here:

  • <qty> and <quantity> are both valid
  • The meaning is defined by the developer or application

This flexibility is powerful but requires agreement between systems.

XML Declaration

Most XML documents begin with a declaration:

<?xml version="1.0" encoding="UTF-8"?>

This defines:

  • XML version
  • Character encoding (important for international data support)

XML Syntax Rules (Modern Explanation)

XML must follow strict rules to ensure it can be parsed correctly.

1. Single Root Element

Every XML document must have exactly one root element:

<list>    ... </list>

2. Properly Closed Tags

Every opening tag must have a closing tag:

<name>Noodles</name>

Self-closing tags are also allowed:

<item />

3. Proper Nesting

Correct:

<item>    <name>Noodles</name> </item>

Incorrect:

<item>    <name>Noodles</item> </name>

4. Case Sensitivity

XML is case-sensitive:

<Name>Valid</Name> <name>Different tag</name>

These are treated as different elements.

5. Valid Tag Names

Rules for tag names:

  • Cannot contain spaces
  • Must start with a letter or underscore
  • Can include letters, numbers, hyphens, and underscores
  • Cannot start with numbers or punctuation

6. Attributes Must Be Quoted

<item id="1" category="food">

XML in Modern Systems

Although less common in modern web APIs, XML is still widely used in:

1. Enterprise Applications

  • Banking systems
  • Insurance systems
  • Government data exchange

2. Configuration Files

  • Android app configurations
  • Microsoft Office documents (DOCX, XLSX internally use XML)
  • Build systems (Maven, Gradle parts)

3. Web Services (SOAP)

  • SOAP APIs use XML as the standard message format
  • Still used in legacy enterprise integrations

XML vs JSON in Modern Web Development

JSON (dominant today)

  • Lightweight
  • Easier to read/write
  • Native support in JavaScript

Example:

{  "name": "Noodles",  "qty": 3 }

XML (structured and verbose)

  • More rigid
  • Supports attributes and schema validation
  • Better for complex document structures

XML Validation (Modern Concept)

Modern XML systems often use:

  • DTD (Document Type Definition) – basic validation
  • XSD (XML Schema Definition) – advanced validation and typing

These ensure data consistency in large systems.

Summary

XML is a structured data format designed for portability and clarity. While modern web applications increasingly use JSON for data exchange, XML remains critical in enterprise systems, configuration files, and legacy web services.

Its strengths include:

  • Strict structure
  • Self-describing data
  • Strong validation support
  • Long-term enterprise stability

Even in modern architectures, XML continues to coexist with newer formats, especially where reliability and formal structure are required.

Comments