XML Tutorial: Structure, Syntax & Survival Skills
XML predates JSON and still runs enterprise integration, document formats, and protocols like SOAP and RSS. This tutorial covers the 20% of XML you need to handle 95% of real encounters.
In short
XML structures data as a tree of nested elements with an optional declaration, exactly one root element, and attributes for small metadata. Well-formed XML requires matched tags, strict nesting, quoted attributes and escaped special characters (&, <, >, ", '); validity additionally requires conforming to a schema like XSD. Namespaces let vocabularies mix safely in one document.
Anatomy of a document
An XML document is a tree of elements. Each element has an opening tag, content (text and/or child elements), and a matching closing tag. Exactly one root element wraps everything; an optional declaration states version and encoding. Attributes attach name="value" metadata to opening tags.
<?xml version="1.0" encoding="UTF-8"?>
<order id="ORD-2026-0612" priority="high">
<customer vip="true">
<name>Ada Lovelace</name>
</customer>
<items>
<item sku="KB-75" qty="1"/>
<item sku="MS-12" qty="2"/>
</items>
</order>Elements vs attributes
Both store data; convention decides which. Attributes suit small, single-valued metadata (ids, flags); elements suit content, anything repeatable, and anything that might grow structure later. When converting XML to JSON, attributes typically surface with an @ prefix — which is exactly how our XML to JSON converter keeps them from colliding with child elements.
The five characters you must escape
Inside text and attribute values, five characters have predefined entities: & for &, < for <, > for >, " for double quote, ' for apostrophe. The unescaped ampersand is the single most common cause of invalid XML in the wild — every URL with ¶m= breaks a feed until escaped. For literal blocks (code samples, scripts), CDATA sections <![CDATA[ ... ]]> switch escaping off entirely.
Well-formed vs valid — and the errors that matter
Well-formed means the syntax rules hold: matched tags, strict nesting (<b><i></b></i> is illegal), quoted attributes, one root, legal characters. Valid additionally means conforming to a schema (XSD/DTD) — a vocabulary contract. Most real-world breakage is well-formedness: a tag closed in the wrong order, an unescaped &, content before the declaration. A validator that reports the exact line and column — like our XML Validator — turns each into a ten-second fix.
Namespaces (xmlns) are the last survival skill: they qualify element names so vocabularies can mix (SOAP envelopes wrapping your payload). You rarely write them; you constantly read them. The prefix is just a local alias for the URI — soap:Body and env:Body can be the same element.
Sources
Frequently asked questions
What is XML actually used for in 2026?
More than its reputation suggests: enterprise integration (SOAP, WSDL), document formats (DOCX and SVG are XML), feeds (RSS/Atom), build configs (Maven, Android manifests), sitemaps, and SAML identity flows. You may not choose XML, but you will meet it.
What's the difference between XML and HTML?
HTML is one specific vocabulary for documents, with browser-defined leniency. XML is a meta-format for defining your own vocabularies, with strict rules: every tag closes, nesting is exact, case matters. HTML forgives; XML refuses.
What is an XML namespace in one sentence?
A URI label that qualifies element names so two vocabularies can share one document without colliding — the prefix (soap:, xsl:) is just a local alias for that URI.
Paste any XML into the XML Formatter — format it, validate well-formedness with exact positions, and explore it as a tree.
Practice on real XMLKeep working
Related tools
XML Formatter
Re-indent any XML document into clean, readable markup — comments and CDATA preserved, validation built in.
XML Validator
Strict well-formedness checking with the exact line and column of every violation — fix XML errors in seconds.
XML to JSON
Parse any XML document into clean JSON — repeated elements become arrays, attributes preserved, text nodes kept.
SOAP Formatter
Turn captured SOAP envelopes into readable XML — Header and Body cleanly indented, namespaces intact.
XML Viewer
Explore any XML document as an interactive tree — elements, attributes (@-prefixed), and counts at a glance.
XML Editor
A full VS Code editing experience for XML — highlighting, folding, find & replace, validation, and tree view in one place.
XML Parser
Run a real XML parse in your browser — see the structure parsers produce, or exactly where they fail.
XML Minify
Strip every insignificant byte from your XML — smaller payloads for SOAP calls, config files, and storage.
WSDL Formatter
Make machine-generated WSDL readable — messages, portTypes, bindings and services cleanly indented and explorable.
XML Diff
Two XML documents side by side with markup highlighting, so an attribute edit reads differently from a text-node edit at a glance.
XML Escape
The five XML entities, handled both directions — make any text safe inside elements and attributes.
XML URL Encode
Carry XML through URLs intact — well-formedness checked, percent-encoded, decoded back to formatted markup.
XML to CSV
Turn record-style XML into spreadsheet-ready rows — wrapper elements unwrapped, nested fields flattened to columns.
XML to YAML
From angle brackets to clean indentation — XML parsed and re-expressed as readable YAML.
XML to String
Validate your XML, then escape it into a single string literal — ready to embed in JSON fields or source code.
XML to Java
Paste an XML sample, get typed Java models — names, nesting and nullability inferred for you.
XML to C#
Paste an XML sample, get typed C# models — names, nesting and nullability inferred for you.
XML to TypeScript
Paste an XML sample, get typed TypeScript models — names, nesting and nullability inferred for you.
XML to Python
Paste an XML sample, get typed Python models — names, nesting and nullability inferred for you.
XML to Go
Paste an XML sample, get typed Go models — names, nesting and nullability inferred for you.