1. XML Introduction

What you will learn

  • What XML is and what it is used for
  • How XML differs from HTML
  • How to create and open a first XML file

What is XML?

XML stands for eXtensible Markup Language. It is a text format for storing and sending data in a way that both people and programs can read. You invent your own tag names to describe your data.

  • XML does not do anything by itself. It only describes information.
  • Software reads (parses) the XML and decides what to do with it.

A first look

XML code: book.xml

<?xml version="1.0" encoding="UTF-8"?>
<book>
  <title>Learning XML</title>
  <author>Sam Rivera</author>
  <year>2026</year>
</book>

What it means

A book with a title (Learning XML), an author (Sam Rivera), and a year (2026). The tag names book, title, author, and year were chosen by the person who wrote the file. They are not built into XML.

XML versus HTML

HTML XML
Purpose Show content in a browser Describe and carry data
Tags A fixed set (p, h1, a) You make up your own
Errors Browsers forgive many mistakes A single mistake can stop a parser
Closing tags Some are optional Always required
Case Tag names are not case sensitive Tag names are case sensitive

They are partners, not rivals. HTML says how a page looks, and XML says what the data is.

What is XML used for?

  • Data exchange between different systems and companies.
  • Feeds such as RSS and Atom, which list a site’s latest posts.
  • Sitemaps that tell search engines which pages exist. WordPress SEO plugins create one for you.
  • Configuration files for many programs, including Android app layouts and manifests.
  • Documents: Word, Excel, and PowerPoint files (.docx, .xlsx, .pptx) are zipped XML.
  • Graphics: SVG pictures are XML.

Many web services now prefer JSON, which is shorter. XML is still common where documents, mixed text, strict rules, or long-lived standards matter. A later lesson compares the two.

Try it yourself

  1. Open a code editor such as Visual Studio Code.
  2. Create a new file and save it as book.xml. Make sure the ending is .xml and not .xml.txt.
  3. Copy the XML above into it and save.
  4. Open the file in a browser (drag it onto the window, or right-click and choose Open with).

What you should see

Most browsers show the file as a tree of nested tags, often with a note such as “This XML file does not appear to have any style information”. That is normal, because you have not told the browser how to style it. If you break the XML on purpose, for example by deleting a closing tag, the browser shows an error message instead.

Different browsers display raw XML in slightly different ways. What matters is that the file opens without an error message.

Why the strictness helps

Because the rules are strict, any program can read any XML file the same way. The strictness is what makes XML dependable for exchanging data.

Common mistakes

  • Thinking XML displays or styles content like HTML.
  • Expecting XML to forgive a missing closing tag.
  • Saving the file as .txt, so it does not open as XML.
  • Assuming tag names such as title have a built-in meaning.

Exercise

Create a file pet.xml that describes a pet with a name, a type, and an age. Open it in a browser and check that it shows without an error.

Show solution
<?xml version="1.0" encoding="UTF-8"?>
<pet>
  <name>Luna</name>
  <type>Cat</type>
  <age>3</age>
</pet>

Any sensible names will do, as long as every tag is closed and the structure is nested properly.

Knowledge check

1. What does XML stand for?

eXtensible Markup Language.

2. Does XML have a fixed set of tags like HTML?

No. You create your own tag names.

3. Name two things XML is used for.

For example: data exchange, RSS feeds, sitemaps, configuration files, SVG graphics, and Office documents.

Summary

  • XML is a strict text format for describing and carrying data, with tags you invent.
  • It differs from HTML in purpose, strictness, and case sensitivity.
  • You can create an .xml file and open it in a browser to check it.
Scroll to Top