XML formatter

This XML formatter takes the text you paste below, indents the elements cleanly, can minify everything to one line and shows line and column when something is wrong. Your data stays in the browser.

Source: W3C – Extensible Markup Language (XML) 1.0: Well-Formed XML Documents. Updated: .

My Toolbox

Paste XML or open a file – it is checked on every change.

Your text stays in your browser – it is not sent, not stored and not added to the address bar.

You can also drop a file onto the text field. It is only read in your browser, not uploaded.

Tree view
XPath query

Supported: /a/b, //b, *, .., @attribute, text(), [2], [last()], [@id='2'], [price>10], contains(), starts-with(), not(), and, or, a | b, count(...). Names without a prefix also match elements with a namespace prefix.

    Result

    Result
    <?xml version="1.0" encoding="UTF-8"?> <catalog> <book id="1"> <title>First book</title> <price currency="EUR">9.90</price> </book> <book id="2"> <title>Second book</title> <price currency="EUR">14.50</price> </book> <!-- end --> </catalog>
    Summary
    7 elements, maximum depth 3. Size: 229 → 266 bytes (16.2 % larger).
    This checks well-formedness (tags, names, attributes, exactly one root element), not schema or DTD. Text between tags is reduced to single spaces when formatting.

    How it is calculated

    Formatting XML means putting each element on its own line and indenting by level. <a><b>1</b></a> becomes a readable tree with <b> one level below <a>.

    What the formatter does

    It splits the text into declaration, comments, CDATA, DOCTYPE, tags and text, checks the order of the tags and rebuilds the document with the chosen indentation. Elements that contain only text stay on one line. Minifying removes all whitespace between the tags and, if you like, the comments too.

    Finding errors

    Element and attribute names, unquoted attributes, duplicate attributes and a bare “&” are checked too. DTD and schema rules are not checked. Everything is processed entirely in the browser.

    Tree view, XPath and JSON

    Security: DOCTYPE and entities

    The formatter reads XML with its own tokenizer and does not use the browser’s XML parser. A DOCTYPE stays plain text: external DTDs and entities are never loaded, and self-defined entities are not expanded. Attacks through external entities (XXE) or exploding entities therefore have no effect.

    Frequently asked questions

    How can I format XML online?

    Paste the XML into the field and choose “Format”: the elements are indented with 2 or 4 spaces or a tab. Everything happens in your browser.

    How do I find errors in an XML file?

    The formatter checks well-formedness and reports the first problem with line and column, for example a wrong or missing end tag.

    Is my XML uploaded?

    No. Formatting and checking run locally in your browser; nothing is sent to a server.

    How do I query XML with XPath?

    Open “XPath query” and type an expression, for example //book[@id=2]/title. The matches are listed with their path. A subset of XPath 1.0 is supported.

    Can I convert XML to JSON?

    Yes, choose “Convert to JSON”. Attributes appear as “@name”, repeated elements as an array, and values stay strings.

    Is it safe to open XML files from others?

    The formatter never loads anything and does not expand entities from a DOCTYPE, so attacks through external entities (XXE) do not work here.

    Sources and legal basis

    As of: · Editorial policy

    Related tools