What Is XML? Meaning, Format Rules, Example XML File and Uses

Sunucun 4 min read

XML, short for Extensible Markup Language, is a markup language used to store and transport data by structuring it with tags in a way that both people and programs can read. It was standardised by the W3C (World Wide Web Consortium); its first version, XML 1.0, was published in 1998. Unlike HTML, it has no predefined tags: you choose the tag names to fit the data (for example <book>, <price>).

Illustration: What Is XML? Meaning, F…

Example XML File

<?xml version="1.0" encoding="UTF-8"?>
<library>
  <book id="1" lang="en">
    <title>Les Misérables</title>
    <author>Victor Hugo</author>
    <price currency="TRY">250</price>
  </book>
  <book id="2" lang="en">
    <title>Pride and Prejudice</title>
    <author>Jane Austen</author>
    <price currency="TRY">180</price>
  </book>
</library>

The first line is the XML declaration (version and character encoding). <library> is the root element; all the data is inside it. The <book> elements are children of the root. Expressions such as id="1" are attributes, and the text between the tags is the element’s value.

Basic Rules of the XML Format

A document that follows these rules is called well-formed XML; a document that does not will cause an error in XML parsers:

  • The document must have a single root element.
  • Every opened tag must be closed: <name>...</name>, or <name/> for an empty element.
  • Tags must be nested in the right order: <a><b></b></a> is correct, <a><b></a></b> is wrong.
  • Tag names are case-sensitive: <Book> and <book> are different.
  • Attribute values are written in quotes.
  • In text, the characters & and < are written as &amp; and &lt;.

Which elements and attributes a document may contain can also be defined with a schema (XSD or DTD); a document that matches its schema is called valid XML.

The Difference Between XML, HTML and JSON

XMLHTMLJSON
PurposeStructuring and transporting dataDisplaying a web pageTransporting data (especially in APIs)
TagsUser-definedPredefined (p, div, a…)No tags; key-value pairs
RulesStrict; does not tolerate errorsBrowsers tolerate errorsStrict syntax
Size / readabilityLonger–Shorter, easy to process in programs
Extra featuresSchema validation, namespaces, attributes–Built-in number, boolean and array types

New web APIs mostly prefer JSON; XML is common in document formats, official data exchange and systems that need schema validation. For JSON see our article what is JSON, and for HTML what is HTML.

Where Is XML Used?

  • Sitemaps (sitemap.xml): The file that tells search engines about a site’s pages.
  • RSS / Atom feeds: The new-content feeds of blogs and news sites.
  • e-Invoices and e-Archive: In Türkiye, e-invoice documents are created with an XML-based standard called UBL-TR.
  • Office documents: .docx, .xlsx and .pptx files are compressed packages that contain XML files.
  • SVG images: Vector graphics are defined with XML.
  • Configuration and data exchange: The settings files of many applications, SOAP web services, and integrations in banking and between institutions.

How to Open an XML File

  • Browser: Drag the .xml file into Chrome, Edge or Firefox; it is shown as a tree.
  • Text editor: You can open and edit it with Notepad, Notepad++ or Visual Studio Code.
  • Excel: It can be imported as a table with Data > Get Data > From XML.
  • e-Invoice XML: Rather than the raw XML, it is opened as a readable invoice with the Revenue Administration (GİB) portal or your integrator’s viewer.

If you are looking for a fast and reliable environment for your site’s sitemap.xml and your web services, take a look at our hosting and VPS server plans.

Frequently Asked Questions

Is XML a programming language?

No. XML is a markup language; it describes data but does not do anything by itself. It is the programs that use XML that read and process the data.

What is the biggest difference between XML and HTML?

HTML describes how data should look, while XML describes what the data is. HTML’s tags are fixed; in XML you define the tags yourself.

Why does my XML file give an error?

The most common causes are an unclosed tag, wrong nesting, more than one root element, an unescaped & sign in the text, or a mismatch between the encoding in the declaration and the file’s actual encoding.

Categories

Latest guides