XML Formatter & Validator
Pretty-print or minify XML, find syntax errors and browse it as a tree
Loading the tool…
Formats XML that is on one line or badly indented, and when there is a syntax error, shows its line, column and how to fix it. Use it to read or repair configuration files, API responses, SVG, RSS and other XML.
How to use
- Paste XML into "XML input" or press "Open file". Correct XML shows "Well-formed XML"; otherwise "Not well-formed" appears with the position.
- Choose 2 spaces, 4 spaces or a tab under "Indentation", or "Minify" for one line. "Each attribute on its own line" and "Remove comments" are also available.
- On the "Tree" tab, expand and collapse elements and select one to "Copy XPath". On the "XPath" tab, press "Run" to evaluate an expression.
- The "JSON" tab shows the document converted to JSON. Copy a result or press "Save as .xml" or "Save as .json".
How it works
- The check follows the XML 1.0 rules for a well-formed document: one root element, matching tags, quoted attributes and declared entities. It does not validate against a DTD or an XSD schema.
- In the JSON result, attributes become keys starting with @, text next to them goes in #text, and repeated child elements with the same name become an array. All values stay strings.
- Your XML is processed only in this browser. It is not saved or sent anywhere. Files over 60 MB cannot be opened.
Questions and answers
- How do I find where the error is in my XML?
- An error comes with its line and column number, the cause and a hint for fixing it. Press "Go to the error" to jump to that spot in the input.
- Why does an & character cause an XML error?
- In XML a literal ampersand must be written as &. Only five entities are predefined, < > & " and ', so an HTML name such as must be written as  .
- Can I convert XML to JSON?
- Yes, on the "JSON" tab. An id attribute becomes the key "@id", and an element with only text and no attributes becomes a plain string. Press "Save as .json" to download it.
- How do I test an XPath expression?
- Enter an expression such as //book/title or count(//book) in "XPath expression" on the "XPath" tab and press "Run". It runs on the browser's XPath 1.0 engine.