XML Formatter and Validator
FV-03Paste XML and press Format to indent it so you can read it, or Minify to strip the whitespace. Both check that every tag is opened and closed in order and name the line of the first mismatch. It runs in your browser and nothing is uploaded.
Runs in your browser. Nothing is uploaded.
XML
Result
How to use it
- Paste your XML into the input box.
- Choose 2 spaces, 4 spaces or a tab for the indent.
- Press Format to beautify the XML, or Minify to remove the whitespace between tags.
- If an error appears, go to the line it names, fix the tag, and run it again.
- Copy the result.
What Format does
Each element goes on its own line, indented one level deeper than its parent. An element that holds only text stays on one line, such as a title with its value. The declaration, comments, CDATA sections, processing instructions and DOCTYPE are kept as written, and attributes are not changed. Text between tags is trimmed and runs of whitespace become one space, so do not use the output where exact whitespace inside text matters.
What the check covers
The check is for well-formed structure. It confirms that every tag is closed in the right order, that there is exactly one root element and that no text sits outside it, and it reports the first problem with its line number. It does not validate against an XSD or DTD schema and does not resolve entities. It also does not check attribute values, so a bare & in text is not reported.
Minify and reading large files
Minify removes the whitespace between tags and trims text, and keeps comments and CDATA. Use it to shrink a payload or to compare two documents without formatting noise. Use Format as an XML viewer for a response copied from an API: the structure shows at a glance, and the same check that Format runs will tell you where a tag is missing before you start debugging the data.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
Expected </item> (opened on line 2) but found </list> on line 5 | A closing tag does not match the element that is still open, usually a missing closing tag or tags closed in the wrong order. | Close </item> before </list>, or check for a typo in the tag name. Names are case sensitive. |
<row> opened on line 4 is never closed | The document ends while an element is still open. | Add </row> where the element should end, or make it self-closing with <row/>. |
Closing tag </b> has no matching opening tag, at line 7 | A closing tag appears with nothing open to close. | Remove the extra closing tag or add the opening tag it belongs to. |
Text outside the root element at line 9 | There is text after the root element ends, or before it begins. | Move it inside the root element or delete it. |
An XML document can have only one root element | Two or more top-level elements sit side by side. | Wrap them in a single parent element. |
Unexpected "<" at line 3 | A < appears that does not begin a valid tag. | Write a literal less-than sign as < or check for an unfinished tag. |
Questions people ask
How do I format XML online?
Paste your XML into the box, choose an indent and press Format. Each element goes on its own line, indented under its parent. The formatting runs in your browser and nothing you paste is uploaded.
Does it validate XML against an XSD or DTD?
No. It checks that the XML is well-formed: tags are opened and closed in order, there is one root element and no text outside it. It does not validate against a schema and does not resolve entities.
How can I check whether my XML is well-formed?
Press Format or Minify. Both run the same structure check, and if a tag is out of order or missing you get a message with the line number of the first problem. Fix it and run it again to find the next one.
Does formatting change my XML data?
Tags, attributes, comments, CDATA and the declaration are kept as written. Text between tags is trimmed and runs of whitespace become one space, so avoid the output where whitespace inside text is meaningful.
Why do I get Unexpected < at line?
A less-than sign appears that does not begin a valid tag. Write it as < if it is meant as text, or finish the unclosed tag on that line.
Can I minify XML here?
Yes. Press Minify to remove the whitespace between tags and trim text. Comments and CDATA are kept. It runs the same structure check first, so malformed XML is reported rather than minified.
About this tool
Checks that every tag is opened and closed in the right order and tells you where the first mismatch is. It checks structure only: it does not validate against a schema or resolve entities.