Skip to content
Format XML

XML Basics

What Is XML Format?

A plain-language guide to the markup language that still powers configs, feeds, APIs, and document standards across the software industry.

XML in one paragraph

XML (eXtensible Markup Language) is a text-based format for storing and exchanging structured data. Unlike HTML, which has a fixed set of tags for displaying web pages, XML lets you define your own tags to describe any kind of information — a product catalog, a configuration file, a news feed, or a vector drawing. The data is human-readable (it is plain text) and machine-parseable at the same time, which is why XML became the default wire format for enterprise systems in the 2000s and still holds that role in many industries today.

Basic syntax: elements, attributes, and text

An XML document is a tree of elements. Every element has an opening tag and a closing tag, and may contain text, other elements, or both. Here is a minimal example:

<?xml version="1.0" encoding="UTF-8"?>
<book isbn="978-0-596-10206-7">
  <title>XML Pocket Reference</title>
  <author>Simon St. Laurent</author>
  <year>2005</year>
</book>

A few rules that every XML file must follow:

  • Exactly one root element wraps the entire document (<book> above).
  • Every opening tag must be closed — either with a matching closing tag or a self-closing slash (<br />).
  • Tags are case-sensitive. <Book> and <book> are different elements.
  • Attribute values must be quoted — single or double quotes both work.
  • Special characters like <, &, and " inside text or attribute values must be escaped with entities (&lt;, &amp;, &quot;).

A document that follows all these rules is called well-formed. If it also matches a schema (DTD, XSD, or Relax NG) that defines which elements and attributes are allowed, it is called valid. Most tools — including our XML validator — check well-formedness; schema validation is a separate step.

CDATA, namespaces, and processing instructions

Beyond plain elements and attributes, XML has a few constructs that show up in real-world files:

CDATA sections

A CDATA block lets you embed raw text without escaping special characters. It starts with <![CDATA[ and ends with ]]>. Common use case: storing HTML snippets or code inside an XML feed.

<description><![CDATA[
  Price is <b>$9.99</b> & available now.
]]></description>

Namespaces

Namespaces prevent name collisions when elements from different vocabularies appear in the same document. A namespace is declared with an xmlns attribute and typically bound to a prefix:

<root xmlns:dc="http://purl.org/dc/elements/1.1/">
  <dc:title>Namespaced title</dc:title>
</root>

Processing instructions

The XML declaration at the top of a file (<?xml version="1.0"?>) is the most common processing instruction. Others, like <?xml-stylesheet?>, tell applications how to handle the document.

Where XML is used today

JSON has replaced XML for most new web APIs, but XML remains the standard in many areas:

  • Configuration files — Maven pom.xml, .NET .csproj, and Android layouts are all XML.
  • Document standards — OOXML (.docx, .xlsx) and ODF are ZIP archives of XML files.
  • Feeds — RSS and Atom feeds that power podcast apps and news readers are XML.
  • Vector graphics — SVG is an XML dialect used on virtually every website.
  • Enterprise integration — SOAP web services, SAML authentication, HL7 healthcare messages, and XBRL financial reports all use XML.
  • Geographic data — KML (Google Earth) and GML carry map data as XML.

XML vs. JSON: when to use which

The two formats solve different problems, and the right choice depends on context:

XMLJSON
VerbosityMore verbose (opening + closing tags)Compact (curly braces, no closing tags)
Schema supportXSD, DTD, Relax NG — mature and strictJSON Schema — lighter, less adoption in older systems
Mixed contentNative (text interspersed with elements)Not supported
AttributesYes — metadata on elementsNo equivalent
NamespacesBuilt-inNot built-in
Browser parsingDOMParserJSON.parse (faster)

Rule of thumb: use JSON for new REST APIs and front-end data exchange. Use XML when you need schemas with strict validation, mixed content (like rich text), or you are working with an ecosystem that already speaks XML (SOAP, SAML, RSS, SVG, Office documents).

Common XML errors and how to fix them

Most XML parsing failures boil down to a handful of mistakes:

  1. Mismatched tags <item>...</Item>. Remember, XML is case-sensitive.
  2. Unescaped ampersands Tom & Jerry should be Tom &amp; Jerry.
  3. Unquoted attribute values <img src=logo.png /> is invalid; wrap the value in quotes.
  4. Multiple root elements — a well-formed document needs exactly one. Wrap siblings in a container element if needed.
  5. Encoding mismatch — the declaration says UTF-8 but the file is saved as ISO-8859-1. Re-save in the declared encoding.

To find these errors quickly, paste your XML into the Format XML tool. It reports the error type, line, column, and the offending source line so you can fix the problem in seconds.

How to format an XML file

Raw XML — especially API responses or minified config files — is hard to read without proper indentation. You have three main options:

  • Command line xmllint --format file.xml works on Linux and macOS. It may normalize attribute order.
  • IDE plugins — VS Code, IntelliJ, and Eclipse all have XML formatting built in or available as extensions.
  • Online formatter — the fastest option when you just need to read a file. Our XML formatter handles files up to 5 MB, preserves attribute order and quote style, and runs entirely in your browser — nothing is uploaded.

Try it now

Paste any XML into the formatter and see it indented and validated in real time — free, no signup, works offline.

Open Format XML