# XML Formatter > Free in-browser tool that formats messy XML into readable XML, with indent, comment and declaration controls, a minify mode, well-formedness validation with line and column errors, and XML to JSON conversion. Independent tool, not affiliated with the W3C. Updated 2026-11-10. Full page: https://lab.awaara.cn/xml-formatter/ ## What it does - Formats XML pasted into the page: each element goes on its own line, indented one level under its parent. Elements that hold only text stay on one line. Empty elements keep the form written: `
` stays self-closing, `

` stays open and closed. - Indent: 2 spaces, 4 spaces, or a tab. - Minify: removes all whitespace between tags and collapses the document. Text, attribute values, and CDATA sections are kept as-is. - Validate: checks well-formedness only, and reports the first error with its line and column, plus a button that jumps to that line in the input. It does not validate against a schema or DTD. - Convert to JSON: maps elements to objects, attributes to `@name` keys, repeated child elements to arrays, and mixed text to a `#text` key. Numbers stay strings, because XML has no number type. Comments and processing instructions are dropped, and the result says how many were dropped. - `xml:space="preserve"` is respected: an element marked that way keeps its exact line breaks and spaces, while the rest of the document is re-indented around it. - Samples: a sitemap, an RSS item, a SOAP envelope, and a broken document to test error reporting. Files up to 400 KB can be opened from disk. - Copy the result, download it as .xml or .json, or load it back into the input to check the round trip. Input is capped at 100,000 characters; longer input is cut at that point and the result says so. - Everything runs locally in the browser. Nothing is sent to a server; the page works offline once loaded. ## What formatting changes, and what it never changes - Changes: line breaks and indentation between tags, and only there. - Never changes: text inside elements, attribute values and their order, CDATA sections, comments (unless asked to remove them), and processing instructions. - After every format and minify, the page re-parses its own output and compares it with the input. If anything but whitespace changed, it shows the original instead, with a warning. ## Errors it catches - Mismatched close tag: `` closing ``, with the line where the open tag started. - Unclosed tag: a tag opened on one line and never closed. - Multiple root elements: a second root starting after the first one closed. - Unescaped `&`: a bare `&` that starts no entity; write it as `&`. - Unquoted attribute: `id=42` instead of `id="42"`. - Text outside the root element, and a `<` that starts no tag. - A document with no root element at all. ## Code snippets (from the page) - Shell, with xmllint: `xmllint --format input.xml > formatted.xml`. Add `--noblanks` to drop blank text nodes between tags before formatting. - Python, standard library only: `import xml.dom.minidom`, then `xml.dom.minidom.parse("input.xml").toprettyxml(indent=" ")`. Note that `toprettyxml` adds blank lines around text nodes; lxml's `etree.tostring(tree, pretty_print=True)` behaves better. - PowerShell, built in: load with `[xml](Get-Content input.xml)`, then save through `System.Xml.XmlTextWriter` with `Formatting` set to `Indented` and `Indentation` set to 2. ## Sources - W3C, Extensible Markup Language (XML) 1.0: https://www.w3.org/TR/xml/ - MDN Web Docs, XML introduction: https://developer.mozilla.org/en-US/docs/Web/XML - Linux man pages, xmllint(1): https://man7.org/linux/man-pages/man1/xmllint.1.html