XML Formatter

Pretty-print XML with proper indentation, validate it, or minify to one line.

Valid XML

Working with XML

XML predates JSON as the standard data interchange format and remains deeply embedded in enterprise systems, document formats and configuration. SOAP APIs, RSS feeds, SVG images, Android layouts, Maven builds and Office documents are all XML underneath.

This tool pretty-prints XML with consistent indentation, minifies it, and reports whether the document is well-formed.

Key takeaways

  • Well-formed means syntactically correct; valid means it also matches a schema.
  • XML is case-sensitive and every element must be closed.
  • Five characters must be escaped: & < > " and '.
  • Attributes cannot repeat within an element and must be quoted.
  • Whitespace between elements may or may not be significant, depending on the schema.

Well-formed versus valid

Well-formedValid
ChecksXML syntax rulesConformance to a DTD or XSD schema
Elements properly nested and closedRequiredRequired
Correct element names in the right orderNot checkedRequired
Correct data types in attributesNot checkedRequired
Needs a schemaNoYes

This tool checks well-formedness. Schema validation requires the corresponding XSD or DTD and is done with a dedicated validator.

XML syntax rules

  • Exactly one root element containing everything else.
  • Every element must be closed - either <p>...</p> or the self-closing <br/>.
  • Elements must nest properly. Overlapping tags are invalid, unlike in forgiving HTML.
  • Names are case-sensitive. <Name> and <name> are different elements.
  • Attribute values must be quoted, with single or double quotes.
  • Attribute names cannot repeat within the same element.
  • Names must start with a letter or underscore, never a digit, and cannot begin with "xml" in any casing.

The five escaped characters

CharacterEntityMust escape?
&&amp;Always
<&lt;Always
>&gt;Recommended
"&quot;Inside double-quoted attributes
'&apos;Inside single-quoted attributes

An unescaped ampersand is the single most common cause of XML parse failures, because ampersands appear constantly in URLs inside attributes.

CDATA sections let you include a block of text without escaping anything: <![CDATA[ ... ]]>. They are useful for embedding code or markup. The one thing they cannot contain is the sequence ]]> itself.

XML compared with JSON

XMLJSON
VerbosityHigh - closing tags repeat every nameLow
AttributesYes, distinct from child elementsNo - everything is a key
CommentsYesNo
NamespacesYesNo
Schema validationMature - XSD, DTD, RelaxNGJSON Schema, newer
Native to browsersRequires parsingParses directly to objects
Mixed contentHandles text mixed with markupAwkward
Typical use todayDocuments, enterprise systems, configWeb APIs

XML remains the better choice for document-shaped data with mixed text and markup. JSON won the API space because it maps directly onto programming language data structures.

Where you still meet XML

  • SVG - vector graphics are XML documents you can edit in a text editor.
  • RSS and Atom feeds.
  • Office documents. A .docx or .xlsx file is a zip archive full of XML.
  • Android layouts and manifests.
  • Maven, Ant and many build tools.
  • SOAP web services, still widespread in banking, insurance and government.
  • XML sitemaps for search engines.

Security notes

XML parsers have a dangerous default. XML External Entity (XXE) processing lets a document instruct the parser to read local files or make network requests, and many parsers historically enabled it by default. It has been used to read server configuration files and to pivot into internal networks. When parsing untrusted XML, disable external entity resolution and DTD processing explicitly.

A related risk is the "billion laughs" attack, in which nested entity definitions expand exponentially and exhaust memory. Disabling DTD processing addresses both.

Everything runs in your browser. Your data is processed entirely on your own device - nothing is uploaded, logged or stored. That matters when the payload you are debugging contains customer records, API responses or anything else you should not be pasting into a remote service.

Frequently Asked Questions

What does formatting XML do?

It adds consistent indentation and line breaks so the document structure is readable, without changing any content. Minifying does the reverse, stripping whitespace between elements to reduce size.

What is the difference between well-formed and valid XML?

Well-formed means the document follows XML syntax rules - one root element, everything closed and properly nested, attributes quoted. Valid additionally means it conforms to a schema defining which elements may appear where. This tool checks well-formedness.

Why does my XML fail to parse?

The most common cause is an unescaped ampersand, which appears constantly in URLs inside attributes and must be written as &amp;. Other frequent causes are unclosed elements, mismatched case in tag names, and more than one root element.

Which characters must be escaped in XML?

Ampersand and less-than always, greater-than by convention, and quote characters inside attribute values using the matching quote style. There are five predefined entities: &amp;, &lt;, &gt;, &quot; and &apos;.

What is a CDATA section?

A block that tells the parser to treat its contents as literal text with no markup interpretation, written as an opening CDATA marker and a closing one. It is useful for embedding code or HTML without escaping every character. It cannot contain the closing sequence itself.

Is XML still used?

Extensively. SVG graphics, RSS feeds, Office documents, Android layouts, Maven builds, XML sitemaps and SOAP web services are all XML. JSON displaced it for web APIs, but XML remains dominant for documents and in enterprise systems.

Should I use XML or JSON?

JSON for web APIs, where it maps directly onto programming language data structures and is far less verbose. XML for document-shaped data with mixed text and markup, where you need namespaces, comments or mature schema validation.

What is an XXE vulnerability?

XML External Entity processing allows a document to instruct the parser to read local files or make network requests. Many parsers historically enabled it by default, and it has been used to read server configuration and reach internal networks. Disable external entities and DTD processing when parsing untrusted XML.

Related Calculators