What is XML?

What is XML?
XML stands for eXtensible Markup Language. It is an open standard, defined by the W3C consortium and officially published in 1998, that is used to store and transport data in a simple text format readable by both humans and machines. If you have ever seen a file full of tags between the less-than and greater-than signs, such as <name>John</name> or <price>8.50</price>, you already have a rough idea of what an XML document looks like. It is worth clarifying right away what XML is not. It is not a programming language: it has no variables, functions, or conditions, and by itself it does not execute anything at all. It is not a presentation language either: it does not define colors, sizes, or positions on screen. XML is a markup language: it describes the structure and meaning of data and organizes it inside tags that name each piece of information. Presentation is left to another program, which decides how to display that data in each case. A useful way to think about it is a cardboard box with adhesive labels. The box contains data: a product, an invoice, a news story, an inventory. The labels say what each piece of data is: name, price, date, quantity. XML does the same thing with plain text: it wraps each piece of data in a tag that explains what it is, and groups everything into a tree structure that any program can walk from top to bottom. That combination, structured data, plain text, and an open, royalty-free standard, explains why XML sits behind so many technologies people use every day without seeing them: electronic invoicing, RSS news feeds, Office documents, search engine sitemaps, and even data exchange between banks, companies, and governments.What exactly does XML mean?
It is worth taking the name apart, because each of its words says something important:- eXtensible: there is no fixed list of mandatory tags. Any person, company, or industry can create its own tags with the names it needs: a hospital uses <patient> or <diagnosis>, a store uses <product> or <price>. This ability to extend the language is what sets it apart from closed markup formats.
- Markup: these are the marks, that is, the tags that surround content and add information about what each part is, just as a proofreader marks a manuscript with symbols to indicate headings, quotations, or corrections.
- Language: XML has a syntax with precise rules: how tags are opened and closed, where attributes go, and how special characters are represented. The rules are few and easy to learn, but they must be followed to the letter so that any program can understand the document.
The structure of an XML document
Every XML document is built from the same basic pieces: an optional declaration at the start, a root element that contains everything, nested elements that form a hierarchy, attributes that add details to elements, and of course the text that holds the data. Here is the simplest possible example: a catalog with a single product. You can copy this code into a text file, save it as product.xml, and drag it into any browser: Example 1: a well-formed XML document <?xml version="1.0" encoding="UTF-8"?> <catalog> <product id="P-100"> <name>Ground coffee 500 g</name> <price currency="USD">8.50</price> <available>true</available> </product> </catalog> If the browser shows the content neatly arranged and color-coded, the XML is well formed. If it shows an error message, there is a syntax problem. Let us go through each part:- XML declaration: the first line, <?xml version="1.0" encoding="UTF-8"?>, states the version of the language and the character encoding. It is optional, but highly recommended when the text includes accents and special characters.
- Root element: the whole document lives inside a single container element; here it is <catalog>. Without a single root, the document is not valid.
- Elements: an element consists of an opening tag, some content, and a closing tag, like <name>Ground coffee 500 g</name>. Elements can be nested inside one another to form a parent and child tree: <product> contains <name>, <price>, and <available>.
- Attributes: they add extra information inside the opening tag, always in the form name="value". In the example, id="P-100" identifies the product and currency="USD" states the currency of the price.
- Text content: between the opening and closing tags there can be text or more elements. The spaces, line breaks, and indentation in the file do not change the meaning of the document: they are only there to make it more readable for people.
Basic rules of well-formed XML
An XML document is called well formed when it follows the syntax rules of the language. If it does not, no program should process it: unlike web pages, errors here are not tolerated or half-fixed. The essential rules are:- There must be a single root element that contains all the others.
- Every opened tag must be closed. If an element has no content, it can close itself: <image url="photo.jpg"/> is the same as opening and closing in the same spot.
- Tags must nest correctly, never overlapping: <a><b></b></a> is valid, while <a><b></a></b> is not.
- XML is case-sensitive: <Product> and <product> are two different tags.
- Attribute values must be written inside double or single quotes.
- Special characters are represented with entities: < stands for the sign <, > for the sign >, & for the sign &, and " for double quotes.
What is XML used for?
XML is used in every scenario where structured data must move between applications, organizations, or devices. Its most common uses are:- Data exchange between systems: because it is plain text and follows a standard, two applications written in different languages and running on different operating systems can understand each other without trouble. It is the classic format for integration between companies, banks, and government agencies.
- Electronic invoicing: the electronic documents required by many countries are generated, signed, and validated as XML. The format lets the issuer, the receiver, and the tax authority read exactly the same data, with no ambiguity.
- RSS and Atom feeds: blogs, news portals, and podcasts publish their updates as XML feeds that readers check automatically.
- Configuration files: many applications store their settings in XML so they are easy to read, edit, and version.
- Document formats: Office .docx, .xlsx, and .pptx files, the SVG vector image format, and the XML sitemaps used by search engines are XML on the inside.
- Web services: enterprise protocols such as SOAP and technologies such as XSLT, which transforms XML into other formats, remain fully active in the corporate world.
What is the difference between XML and HTML?
XML and HTML belong to the same family, both descend from SGML, and both use tags, which is why they are frequently confused. But their purpose is almost opposite. HTML exists to display content in the browser: its tags, such as <h1>, <p>, or <img>, are fixed by the standard, and the browser knows exactly how to draw each one. XML exists to describe data: the tags are up to you, and no browser gives them a default look. The other big difference is error tolerance. A browser fixes an HTML page with unclosed tags on its own and displays it anyway. An XML processor, in contrast, rejects the entire document if it finds a single syntax violation. And while case does not matter for HTML tags, it does in XML: <Book> and <book> are different elements.| Aspect | XML | HTML |
|---|---|---|
| Main purpose | Store and transport data | Present content on the web |
| Tags | Created by whoever writes the document | Fixed and defined by the HTML standard |
| Presentation | Does not define how data looks | Defines the visual structure of the page |
| Syntax errors | The document is rejected | The browser tolerates them and displays anyway |
| Case | Case-sensitive: <Book> and <book> differ | Not case-sensitive |
What is an .xml file and how do you open it?
An .xml file is simply a text file whose content is an XML document. The .xml extension tells programs what to expect, but inside there is nothing special: just plain text characters. That is why you can open, read, and edit it with the most basic tools you already have installed:- Notepad or any other text editor: right-click the file and choose Open with. You will see the tags exactly as they are stored.
- Web browser: drag the file into Chrome, Firefox, or Edge. If the XML is well formed, the browser shows it as a collapsible, color-coded tree of tags. If it has errors, it points to the exact line that fails.
- Excel: when the file contains tabular data, Excel converts it into rows and columns, which makes it easier to review the information without reading tags.
- Editors with syntax highlighting: tools like Visual Studio Code or Notepad++ color tags, attributes, and values, which makes working with large XML files much more comfortable.