Skip to content

XML Introduction

XML (EXtensible Markup Language) is a language used to describe data.

HTML (HyperText Markup Language) is a language used to display data.

Think of XML as a way to structure and carry information, while HTML focuses on presenting it.

A basic understanding of HTML structure (tags, elements) is helpful for grasping the concept of markup.

  • HTML Basics

While not strictly necessary for understanding XML concepts, knowledge of JavaScript is essential for manipulating XML data within web browsers.

  • EXtensible Markup Language: ‘Extensible’ means you define your own tags, unlike HTML where tags are predefined.
  • Markup Language: Like HTML, it uses tags (<tag>...</tag>) to structure content.
  • Describes Data: Its primary purpose is to store and transport data, focusing on what the data is.
  • Self-Descriptive: The user-defined tags often make the data’s meaning clear (e.g., <customerName>, <orderId>).
  • W3C Recommendation: XML is a mature, standardized technology recommended by the World Wide Web Consortium (W3C).
  • Purpose: XML stores/transports data (focus on meaning). HTML displays data (focus on presentation).
  • Tags: XML tags are user-defined. HTML tags are predefined.
  • Structure: XML is strict about syntax (e.g., closing tags, proper nesting). HTML is more lenient (browsers often try to correct errors).
  • Goal: XML aims for data structure and portability. HTML aims for rendering content in browsers.

XML is not a replacement for HTML; they often work together. XML can hold the data, and HTML (with CSS and JavaScript) can format and display it.

An XML document, on its own, is just structured text. It doesn’t perform any actions.

Consider this XML note:

<?xml version="1.0" encoding="UTF-8"?>
<note priority="high">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

This document clearly describes a note with sender, recipient, heading, body, and priority. However, it just sits there.

Software applications are needed to process this XML: to read it, send it over a network, display it, validate its structure, or transform it into another format.

The power of XML lies in its extensibility. Tags like <to>, <from>, <heading>, <body>, and attributes like priority are not part of the XML standard itself. They were chosen by the creator of this specific XML document to represent their data meaningfully.

This allows XML to model virtually any type of structured data, from configuration files to scientific data to financial transactions.

In modern web development, JSON (JavaScript Object Notation) is often used for data exchange instead of, or alongside, XML. JSON is generally less verbose and maps more directly to JavaScript objects.

However, XML offers features not native to JSON, such as namespaces (for avoiding tag name conflicts), schemas (DTD/XSD for validation), built-in support for comments, and transformation capabilities (XSLT). The choice between XML and JSON often depends on the specific requirements of the application and ecosystem.

XML’s key value proposition is being a software- and hardware-independent standard for structuring and exchanging information.

XML became a W3C Recommendation in February 1998 and remains a foundational technology in many areas.