FormatterNew

XML Formatter and Validator with Error Lines

Pretty-print, minify and validate XML, keeping comments and CDATA intact

100% client-side — your data never leaves your browserNo data stored or uploadedFree for lifetime · No signup

Format, prettify and validate XML in one step

Paste XML and press Format. The page first hands the text to your browser's built-in XML parser (DOMParser with the application/xml type), the same strict parser browsers use for SVG and XHTML. If the document is not well-formed, nothing is reformatted: you get the parser's message, and the line and column where it stopped when the browser reports one. Only well-formed input is pretty-printed, so the XML beautify step can never hide a broken document behind neat indentation.

The formatter then re-indents the document with 2 spaces, 4 spaces or tabs. Each element starts on its own line, and an element that contains only text stays on one line, so <title>XML Developer's Guide</title> is not exploded into three lines. Comments, CDATA sections, processing instructions such as <?xml-stylesheet ?> and the DOCTYPE declaration, including any internal subset, are copied exactly as written; nothing inside a CDATA block is touched, so embedded HTML or script survives. Attribute order and quoting are left alone too.

Everything runs in your browser. The XML you paste is not uploaded, which matters for SOAP payloads, SAML assertions, Maven or .NET config files and product feeds that often contain credentials, account IDs or customer data.

What the XML validator checks, and what it does not

The Validate button checks well-formedness: exactly one root element, every start tag closed or self-closed, correct nesting, quoted attribute values, no duplicate attributes on an element, legal names and properly escaped & and < characters. These are the errors behind most "XML parsing error" messages in feeds, Android layouts and sitemap submissions.

It does not validate against a schema. Checking that a document obeys an XSD, DTD or RELAX NG grammar, for example that <price> must be a decimal, needs the schema file and a validating parser such as xmllint --schema schema.xsd file.xml. Browsers do not perform schema validation, so this page cannot, and it does not pretend to. External entities and DTDs are not fetched either.

Error wording comes from the browser. Chrome and Edge report something like "error on line 3 at column 15: Opening and ending tag mismatch", Firefox says "XML Parsing Error: mismatched tag" with a line number, and Safari is similar to Chrome. Look at the reported position and the line just above it: an unclosed tag usually triggers the error where the parser finally notices, not where the tag was opened.

Indentation, whitespace and minifying

XML treats whitespace between elements as text, so any formatter changes it. This one treats whitespace-only text between tags as insignificant, which is right for configuration, data and feed files. For mixed content, where text and child elements sit side by side, text runs are trimmed and placed on their own lines. Elements marked xml:space="preserve" are emitted exactly as written. Minify does the reverse: it removes whitespace-only text between tags, keeps comments unless you tick Strip comments, and leaves CDATA alone, which shrinks the payload before you embed it in a request or a test fixture.

Output lines are joined with Unix line feeds. Formatting already-formatted XML produces the same result, so it is safe to run on files that are partly indented, and minifying then formatting again returns the same layout.

How to use the XML Formatter and Validator with Error Lines tool

  1. 1

    Paste your XML

    Drop XML into the left panel, or load the sample to see how comments and CDATA are handled.

  2. 2

    Choose the indent

    Pick 2 spaces, 4 spaces or tabs to match your project's style.

  3. 3

    Format, minify or validate

    Format pretty-prints, Minify strips whitespace between tags, and Validate only checks that the XML is well-formed.

  4. 4

    Fix errors and copy

    If the parser reports an error, go to the line and column shown, fix it, then copy the formatted output.

Frequently asked questions

Is my XML uploaded to a server?

No. Parsing, formatting and minifying all happen in your browser with DOMParser and plain JavaScript. A share link only stores your input in the URL's # fragment, which is not sent to the server.

Does this validate XML against an XSD schema?

No. It checks that the XML is well-formed, which is what browsers can do. For XSD or DTD validation use a validating parser such as xmllint --schema, or your IDE's XML support with the schema configured.

Will formatting change my CDATA sections or comments?

No. Comments, CDATA sections, processing instructions and the DOCTYPE are copied verbatim. Only whitespace between tags is re-indented, and elements with xml:space="preserve" are left exactly as written.

Why does the error point to the wrong line?

Parsers report where they detected the problem. A missing closing tag is often only noticed when a later, mismatched closing tag appears. Check the reported line and the lines before it.

How do I format XML from the command line?

xmllint --format file.xml pretty-prints with 2 spaces (set XMLLINT_INDENT to change it), and in Python, xml.dom.minidom.parseString(text).toprettyxml(indent=' ') does the same in code.

Get the next tool before you need it

One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.