Format, validate and minify XML in your browser, with exact error locations, comments and CDATA kept as written, and a tree view that copies the XPath of any element.
Runs in your browser
Nothing is uploaded
Free, no sign-up
0 B
Runs in your browser. Nothing is uploaded.Tip: click any element in the Tree view to copy its XPath
Paste XML into the left box, or drop an .xml, .svg, RSS or sitemap file onto it. Small inputs are checked as you type; for large files press Format.
Choose Format (2 spaces, 4 spaces or tabs) or Minify. Tick One attribute per line for long tags, or Self-close empty tags to write <tag></tag> as <tag/>.
If the XML is not well-formed, the message under the tool gives the line, column and a preview. Press Show me to jump to the problem.
Switch the output to Tree to explore the document. Click an element, attribute or text to see and copy its XPath, such as /urlset/url[2]/loc.
XML (Extensible Markup Language) is a text format that stores data as a tree of named elements, such as <price currency="USD">44.95</price>, with attributes, text, comments and CDATA sections. It is defined in the W3C XML 1.0 specification and is still everywhere: sitemaps, RSS and Atom feeds, SVG images, SOAP APIs, Android layouts, Maven pom.xml files, Office documents and many configuration files.
Well-formed XML follows the syntax rules: one root element, every tag closed in the right order, quoted attribute values and escaped special characters. Every XML parser rejects a document that is not well-formed. Valid XML is well-formed and also matches a schema (a DTD or an XSD) that says which elements and attributes are allowed. This tool checks that your XML is well-formed. It does not check it against a schema.
Many formatters parse XML into objects and write it back, which can drop comments and the DOCTYPE, change attribute quotes, decode entities or trim the text inside elements. This tool reformats the original text instead, so comments, CDATA, the DOCTYPE, entities, attribute order and quote style stay exactly as written. Elements that mix text and tags, such as <p>Hello <b>you</b></p>, and elements with xml:space="preserve" are left untouched, because adding line breaks there would change the text. Only the whitespace between tags changes.
Your XML is checked twice: first by fast-xml-parser, which gives clear messages, then by your browser's own XML parser, which also catches problems such as undefined entities.
XPath is a query language that points at parts of an XML document. The tree view gives you the exact path of any node, ready for your code or xmllint --xpath.
XPath
Selects
/catalog/book
Every book element directly under the root catalog
$dom = new DOMDocument();$dom->preserveWhiteSpace = false; // set before loading$dom->formatOutput = true;$dom->loadXML($xml); // false when the XML is not well-formedecho $dom->saveXML();
Expected closing tag 'from' ... instead of closing tag 'frm'
A closing tag does not match the tag that is open. Check the spelling and the case (<Item> and </item> are different), and close tags in the reverse order they were opened.
Multiple possible root nodes found
An XML document can have only one root element. Wrap everything in one element, such as <items>...</items>.
Entity 'nbsp' not defined or an error at an &
Write & as & in text and attribute values. HTML entities like are not part of XML: use   instead.
XML declaration allowed only at the start of the document
Something comes before <?xml ...?>, often a blank line printed by PHP before a sitemap or RSS feed. Remove any whitespace before <?php and after ?> in your files.
Attribute 'checked' is without value
HTML allows attributes without a value, XML does not. Write checked="checked", and always quote attribute values.
Only the whitespace between tags. Comments, CDATA, the DOCTYPE, entities, attribute order and quotes, and the text inside elements stay exactly as written. Elements that mix text and tags are not reformatted at all.
Does this tool validate XML against a schema (XSD or DTD)?
No. It checks that the XML is well-formed, which is what every parser requires. To validate against a schema, use xmllint --schema or a library in your language.
How do I find the error in my XML?
Paste it here. The message under the tool gives the line and column, shows the line with a caret under the problem, and Show me moves the cursor straight to it.
How do I use the XPath from the tree view?
Paste it into xmllint --xpath, PHP's DOMXPath, Python's lxml or any XPath tester. If the document has a default namespace (xmlns="...", as in sitemaps), most libraries need you to register a prefix for it first.
How large an XML file can I format?
Files up to 50 MB. Inputs over 1 MB are formatted when you press Format instead of on every keystroke, so typing stays fast.
Is my XML uploaded?
No. Validation, formatting and the tree view all run in your browser, so it is safe to paste API responses and configuration files.