XML Formatter
Paste XML and get it indented, or find the tag that broke it.
What is an XML formatter?
An XML formatter indents a document so the nesting of its elements becomes visible, and can do the reverse, stripping the whitespace back out to make the file smaller. It changes layout only: elements, attributes and text come out unchanged.
How it works
The formatter walks the document tag by tag and re-indents it: one level per level of nesting, one element per line, with a short value kept on the same line as the tags around it.
It keeps a stack of what is open. A closing tag that does not match the top of that stack is the error, and the tag it names is almost always where the mistake is, which is more useful than "not well-formed" at the end of the file.
Comments and CDATA sections end on their own terminator rather than the next angle bracket, so a > inside either one never splits the document in the wrong place.
What an XML formatter does, and what "well-formed" means
XML from a system is usually one unbroken line, because whitespace between elements carries no meaning and nothing generating it has a reason to add any. A formatter puts that structure back on the screen: an element per line, indented by depth, so the shape of the document is visible at a glance.
Doing it requires understanding the nesting, which is why the same tool answers the other question people arrive with: is this well-formed? Well-formed is the lower bar of the two XML has. It means every opened tag is closed, closing tags are in the right order, attributes are quoted, and there is one root element. It says nothing about whether the document matches a schema: that is validity, a separate and larger check that needs the XSD or DTD.
The four things that break an XML file
- An unclosed tag the commonest by far, and the reason the error so often points at the end of the file: the parser kept reading happily until it ran out. The tool names the tag still open instead, which is where to look.
- Tags closed out of order <b><i>text</b></i> is valid in sloppy HTML and never valid in XML. Elements nest; they do not overlap.
- An unescaped & or < inside text these are markup, not characters. Write & and <, or put the text in a CDATA section.
- More than one root element an XML document has exactly one. Two top-level elements usually means two documents were concatenated, which is a common accident when a log is assembled by appending.
Formatting, minifying, and when to use which
Indenting is for reading and for diffing. A formatted file compares line by line, so a change shows up as the lines that changed rather than as one enormous line that differs. Format both sides before a diff and the comparison becomes useful.
Minifying is for sending. Whitespace between elements is insignificant in XML, so stripping it is lossless for the structure and can take a noticeable fraction off a large SOAP envelope or an RSS feed. The one caution is mixed content, elements that contain both text and child elements, as in XHTML, where the spaces between words are inside the text and must survive; this tool only touches whitespace between tags, never inside text.
XML next to JSON
The two formats answer different questions, and a file in one is rarely a clean file in the other. XML has attributes, namespaces, comments, processing instructions, mixed content and a schema language; JSON has objects, arrays and four scalar types. Converting XML to JSON forces a decision on every one of those features, does an attribute become a key with an @ prefix, what happens to a namespace, is a single child element an object or an array of one, and different converters decide differently, which is why a round trip through JSON rarely returns the XML you started with.
Where you meet XML today is usually somewhere that predates JSON or needs what JSON lacks: SOAP services, RSS and Atom feeds, sitemaps, Android layouts, Maven and Spring configuration, Office documents, SVG. Most of those have a schema, which is the thing XML has and JSON mostly does not.
Checking a file you should not upload
The whole thing runs in the page. Nothing is sent to a server, so a SOAP response with customer records, a configuration file with a connection string, or an export from a production system can be formatted without any of it leaving your machine, and the tool keeps working with the network disconnected.
That is the difference that matters for XML in particular, because XML is where the old integrations live, and the old integrations are where the sensitive payloads are. An online formatter that posts to a backend has received the document, and whatever it logs, it keeps.
Questions people ask
Why does my XML error point at the last line?
Because a tag further up was never closed, so the parser kept reading until the document ran out. This tool names the tag that is still open instead, which is where the mistake actually is.
Is my XML uploaded?
No. The formatting runs in your browser, nothing is sent anywhere, and the tool works offline. You can paste a production SOAP response safely.
What is the difference between well-formed and valid?
Well-formed means the syntax parses: tags closed, nesting correct, one root. Valid means it also matches a schema: the right elements in the right order with the right types. This tool checks the first; the second needs your XSD or DTD.
Does minifying change my data?
No. It removes only whitespace between tags, which is insignificant in XML. Text inside an element is left exactly as it is, so mixed content survives.
Can I convert the XML to JSON?
Not here, and that is deliberate: attributes, namespaces and mixed content have no single right answer in JSON, so every converter chooses differently and a round trip rarely returns what you started with.