XML Formatter

The formatted result will appear here...

How to use the XML Formatter

The XML Formatter turns compact or messy XML into a clean, indented tree that is easy to read, check and edit. Everything runs in your browser, so your data is never uploaded to a server.

Step by step

  1. Paste your XML into the Input box (it appears above the output on small screens).
  2. Click Format XML. The result appears in the Formatted Output panel as a collapsible tree.
  3. Use the small arrow next to any element to collapse or expand it, which helps when working with large documents.
  4. To change a text value or an attribute value, click it in the output, type the new value and press Enter. Press Esc to cancel.
  5. Click Copy Output to copy the formatted XML to your clipboard, or Clear to remove everything and start over.

Tips

  • Your XML must be well-formed: a single root element and every tag properly closed. If it is not, a red message explains what is wrong so you can fix it and try again.
  • The formatted output uses 2-space indentation, and elements with no content are written as self-closing tags such as <br />.
  • Text inside CDATA sections is not lost; it is written out as regular, escaped text.

Good to know

XML (Extensible Markup Language) describes data with nested tags. A document is well formed when it has a single root element, every opening tag has a matching closing tag, tags are nested correctly, attribute values are quoted and the names match exactly (XML is case sensitive).

Five characters have a special meaning in text and must be escaped: & as &amp;, < as &lt;, > as &gt;, a double quote as &quot; and an apostrophe as &apos;. Forgetting to escape an ampersand is one of the most common reasons a document fails to parse.

When to use it

  • Inspecting an XML feed, SOAP message or configuration file that arrives as one long line.
  • Checking that a document is well formed before you send it to another system.
  • Editing an attribute or value in a tree view without searching through raw text.

Example: Compact input and indented output

Input

<note><to>Lan</to><body>Meet at 9</body></note>

Result

<note>
  <to>Lan</to>
  <body>Meet at 9</body>
</note>

Common mistakes

  • More than one root element. A document needs exactly one.
  • Unclosed or mismatched tags, including differences in letter case (<Name> is not closed by </name>).
  • An unescaped & or < inside text, such as in a URL with several query parameters.
  • Well formed does not mean valid. Checking a document against a schema (XSD) is a separate step.

Frequently asked questions

Is my XML sent to a server?
No. The XML is parsed and formatted in your browser, so nothing you paste is uploaded.
Does it validate my XML?
It checks that the XML is well-formed using the browser XML parser: one root element, correctly matched tags and valid escaping. It does not validate against an XSD or DTD schema.
Why do I get an error message?
The message comes from the browser XML parser. The usual causes are a tag that is not closed or does not match (XML is case-sensitive), an unescaped & or < in text, more than one root element, or text before the root element.
Does it keep comments and the XML declaration?
No. XML comments and processing instructions are not kept, whitespace around text is trimmed, and the formatted output always starts with a standard <?xml version="1.0" encoding="UTF-8"?> line. Keep a copy of the original if you need those.
How are elements without content written?
As self-closing tags, for example <br /> instead of <br></br>.
Can I edit values in the result?
Yes. Click a text value or an attribute value in the tree, type the new value and press Enter. Press Esc to cancel.

Related searches: format xml online free · xml pretty print online · check if xml is well-formed online · xml tree viewer online

Tìm kiếm liên quan: công cụ định dạng xml online miễn phí · kiểm tra xml hợp lệ online · xem cấu trúc xml dạng cây · chỉnh sửa thuộc tính xml online