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.
Because XML only describes data, the same document can look very different depending on who displays it: one program may turn it into a table, another into an on-screen record, and another into a PDF file. The XML stays the same; only the way it is presented changes. That is why XML is said to separate data from presentation, a huge advantage when the same information must flow between systems that do not know each other.

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: &lt; stands for the sign <, &gt; for the sign >, &amp; for the sign &, and &quot; for double quotes.
The next example shows how to write an ampersand inside element content and how to add a comment, which programs completely ignore: Example 2: entities and comments <company>   <name>Smith &amp; Sons</name>   <city code="NYC"/>   <!-- This comment does not affect the data --> </company> Besides being well formed, an XML document can be valid, which is a stricter level: it means that, on top of the syntax, it also complies with a schema or DTD that defines which tags, attributes, and structures are allowed for a specific domain. Electronic invoicing works this way: the document must be well formed, comply with the authority's official schema, and carry a digital signature.

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.
AspectXMLHTML
Main purposeStore and transport dataPresent content on the web
TagsCreated by whoever writes the documentFixed and defined by the HTML standard
PresentationDoes not define how data looksDefines the visual structure of the page
Syntax errorsThe document is rejectedThe browser tolerates them and displays anyway
CaseCase-sensitive: <Book> and <book> differNot case-sensitive
There is also XHTML, a variant of HTML that does follow the strict rules of XML, plus XML-derived languages such as RSS or SVG, which show how versatile the model is. The practical rule is simple: if you need to display information, you use HTML; if you need to represent information so another application can consume it, you use XML.

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.
Do not expect a formatted document like a PDF or a pretty web page: an .xml file shows raw data, and that is precisely its strength, because any system can process it without depending on a specific commercial program.

XML vs JSON: a brief comparison

Whenever data exchange comes up, JSON, JavaScript Object Notation, also appears: it is the format that dominates modern web APIs. JSON is lighter and more compact, written with braces and brackets, includes native arrays, and is read directly by JavaScript, which makes it the natural choice for web and mobile applications. XML keeps the advantage where strict validation through XSD schemas, attributes, namespaces to avoid collisions between different vocabularies, or transformations with XSLT matter. In addition, many established standards, such as electronic invoicing, RSS, or document formats, are built on XML and will not migrate any time soon. In practice, both coexist: JSON for agile APIs between modern applications, and XML when the context demands mature standards, validation, and traceability.

Conclusion

XML is an extensible, open, plain-text markup language used to store and transport structured data between people, programs, and organizations. Its syntax can be learned in a few hours, and yet it supports critical infrastructure: electronic invoices, news feeds, office documents, and integrations between systems that were never designed to work together. Although it now coexists with alternatives such as JSON, XML remains the official language of many business processes. In fact, XML is what makes modern electronic invoicing possible: documents are generated, digitally signed, and validated in this format before they reach the tax authority. Understanding what XML is means understanding the common language in which real-world systems exchange their most important information.
Chatea por WhatsApp