How to use the XML Formatter tool
- Add your XMLPaste it or open a file such as .xml, .svg, .rss or .kml.
- Pick an actionFormat, Minify, XML → JSON or JSON → XML; output refreshes as you type.
- Check validityA green notice confirms well-formed XML, while a red one points to the first problem.
- Copy or saveCopy the output, download it as a file, or feed it back in as the next input.
XML formatter features
- XML pretty printerIndent with 2 spaces, 4 spaces or tabs, keeping short text values on a single line for readability.
- Nothing lostAttributes, comments, CDATA blocks, processing instructions, the XML declaration and DOCTYPE all survive.
- XML validatorRuns your browser’s strict XML parser and reports the line and column of the first error.
- XML ↔ JSON conversionAttributes become “@name”, text becomes “#text” when needed, and repeated elements turn into arrays.
- PrivateData stays on your device, so it’s safe for API responses and internal configuration.
Common XML errors and how to fix them
- Unclosed tag:
<city>Delhineeds its end tag,<city>Delhi</city>, or an empty element can close itself, as in<hr/>. - Overlapping tags:
<p><em>text</p></em>must close in reverse order,</em></p>. - Raw ampersand:
<firm>Smith & Sons</firm>must use&, or put the text inside CDATA. - Unquoted attribute:
<row n=3>has to becomen="3". - More than one root:
<x/><y/>needs a single element wrapping everything. - Content before the declaration: even a space or byte-order mark ahead of
<?xmlis an error, because the declaration must come first. - Mismatched case:
<Order>…</order>fails because XML is case-sensitive, so spell both tags identically.
Well-formed vs valid XML
This validator confirms that XML is well-formed: every tag is closed and properly nested, every attribute is quoted, and there’s exactly one root element. A document can be well-formed yet still not valid for a particular system, which compares it against a schema (XSD or DTD) listing permitted elements. If a sitemap or e-invoice is rejected despite being well-formed, check it against that format’s specification.
How XML is converted to JSON
<movie year="1999"><name>The Matrix</name><genre>sci-fi</genre><genre>action</genre></movie>
{ "movie": { "@year": "1999", "name": "The Matrix", "genre": ["sci-fi", "action"] } }
Attributes receive an @ prefix, an element containing only text becomes a string, and repeated elements become an array. JSON → XML reverses the process. Values stay as text, because XML has no native numbers or booleans.
Formatting vs minifying XML
Formatted XML is easy to read, review and compare in the Text Diff Checker. Minified XML strips the indentation between tags, making it smaller for APIs and storage. Formatting trims whitespace inside text values, so keep the original if spacing within an element matters, as with poetry or code. For JSON, use the JSON Formatter, and to create a sitemap, try the XML Sitemap Generator.