Well-formed XML
- Every opening tag needs a closing tag (
<a>…</a>) or must close itself (<a/>), and tags must close in the reverse order they opened. - A document has exactly one root element.
- Attribute values must be quoted:
id="1", notid=1. <and&in text must be written<and&, or put in a CDATA section.
How to use the XML Formatter
- Paste XML, or press Sample.
- Fix any error: select its location to jump to it.
- Choose the indent, line width and whitespace handling.
- Copy the result or download it.
Examples
A minified document
<?xml version="1.0" encoding="UTF-8"?><catalog><book id="bk101" lang="en"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><price>44.95</price></book></catalog><?xml version="1.0" encoding="UTF-8" ?>
<catalog>
<book id="bk101" lang="en">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<price>44.95</price>
</book>
</catalog>
A Maven dependency with 4-space indentation
<project><modelVersion>4.0.0</modelVersion><dependencies><dependency><groupId>org.junit</groupId><artifactId>junit</artifactId><version>5.11.0</version><scope>test</scope></dependency></dependencies></project><project>
<modelVersion>4.0.0</modelVersion>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit</artifactId>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Mismatched tags
<order><item>Pen</order></order> closes <item>, which is still open. Close <item> first.The error points to line 1, column 17, where </order> is.
Whitespace in text
Reformat (the default) puts each element on its own line, which is right for data and configuration XML, where whitespace between elements doesn't matter. For documents mixing text and markup, such as XHTML or DocBook, choose Keep text spacing, which never adds or removes whitespace inside text.
Options
- Indent
- 2 spaces (the default), 4 spaces or tabs.
- Line width
- Long tags wrap their attributes to stay within it.
- Whitespace
- Reformat (the default) or Keep text spacing, as described above.
- Sort attributes
- Order each element's attributes alphabetically, which makes diffs easier to read.
Limitations
- The tool checks that XML is well-formed, not that it's valid against a DTD or XML Schema (XSD).
- Entities declared in a DTD aren't expanded.
Frequently asked questions
Is my XML uploaded?
No. Checking and formatting run in your browser; nothing you paste is sent anywhere.
What's the difference between well-formed and valid?
Well-formed means the XML follows the syntax rules: nesting, quoting, one root. Valid means it also follows a schema (DTD or XSD) that says which elements and attributes are allowed. This tool checks the first.
Can it convert XML to JSON?
Not yet; XML to JSON is planned. For JSON, the JSON Formatter does the same job as this tool.