XML Formatter
Format, validate, and beautify XML documents with syntax highlighting and error detection
XML Input
Formatted Output
Inspector
Advanced Options
Compare with another XML
Send this document to Data Diff and paste a second version to see what changed.
Validation with the exact error position
Validation runs on every keystroke using the browser XML parser. Well-formed documents get live counts of elements, attributes, text nodes and depth. Broken ones report the exact line and column, a probable cause, and a highlight at the failing position — not just "not well-formed".
Common XML errors this tool pinpoints
These mistakes account for most invalid XML. Each one is detected with a position and a probable cause:
Mismatched tags
<person> closed with </perso>. The parser reports "Opening and ending tag mismatch" with the line of both tags; the highlight jumps to the failing one.
Unclosed tag
A missing > or a missing end tag. Usually reported as "expected >" or "premature end of data in tag X" at the exact position.
Duplicate attribute
The same attribute name twice on one element, e.g. <item id="1" id="2">. Reported as "Attribute redefined" pointing at the second occurrence.
Invalid entity / raw &
A literal & or < inside text must be escaped (&, <). The parser reports "EntityRef: expecting ;" or "not well-formed" at the exact character.
Before / After
Minified API response on the left, the same document formatted with 2-space indent on the right. Structure, tree and paths update from the parsed document.
<catalog><book id="1" category="fiction"><title>The Hobbit</title><author>J.R.R. Tolkien</author></book><book id="2" category="tech"><title>Refactoring</title><author>Martin Fowler</author></book></catalog>
<catalog>
<book id="1" category="fiction">
<title>The Hobbit</title>
<author>J.R.R. Tolkien</author>
</book>
<book id="2" category="tech">
<title>Refactoring</title>
<author>Martin Fowler</author>
</book>
</catalog>
XML quick reference (W3C XML 1.0)
- Well-formed ≠ valid: well-formed means tags nest and close correctly; valid additionally means the document follows a DTD or XSD schema.
- Five predefined entities: < > & " ' — a literal < or & in text is always an error.
- Element and attribute names are case-sensitive and may carry namespace prefixes (ns:tag).
- Exactly one root element; an XML declaration like <?xml version="1.0" encoding="UTF-8"?> must come first if present.
- Comments <!-- … --> may not contain -- and may not be nested.
Next steps with this data
Formatting is the first step. Continue the workflow without leaving your browser:
Frequently Asked Questions
Common questions about Xml Formatter formatting answered
The formatter performs well-formedness checking and basic validation. It checks proper tag nesting, attribute syntax, and XML declaration compliance following W3C XML 1.0/1.1 specifications.
Yes, the built-in XPath tester lets you write and evaluate XPath 1.0 and 2.0 expressions against your XML document, highlighting matching elements and showing results instantly.
Yes, the formatter correctly processes XML documents with namespaces, preserving namespace declarations and prefixes while formatting elements and attributes properly.
Yes, the conversion feature lets you transform XML to JSON and back with intelligent mapping that preserves element structure, attributes, and data types.
The XML formatter supports files up to 50MB with optimized parsing algorithms, making it suitable for large configuration files, SOAP messages, and data interchange documents.
Namespace declarations (xmlns, xmlns:prefix) are treated as ordinary attributes for indentation purposes and are never reordered or dropped, so namespace URIs stay bound to the same prefixes. Formatting never resolves or rewrites prefixes - tools downstream resolve them per the W3C Namespaces in XML recommendation.
Formatting only re-indents and normalizes whitespace between elements. Validation checks structure: balanced tags, one root element, correct attribute quoting, and entity syntax per the W3C XML 1.0 specification. The formatter reports well-formedness errors (malformed input cannot be re-indented) but does not validate against a DTD or XSD schema.
Yes - CDATA blocks keep their exact inner content (that is their purpose: escaping text that would otherwise need entity encoding), and comments pass through unchanged apart from surrounding indentation. XML declarations and processing instructions like <?xml version="1.0"?> also stay at the top untouched.
Authoritative References
Standards and official documentation that define the formats this tool works with.
W3C - Extensible Markup Language (XML) 1.0
The W3C Recommendation defining Extensible Markup Language 1.0, the foundation of the format.
XML - Wikipedia
XML tree model, namespaces, and why the format stresses validity and well-formedness.
MDN Web Docs - XML
Mozilla guide to XML processing in the browser, including DOMParser usage.
Related Tools
JSON Formatter
Format, validate, and beautify JSON data with intelligent indentation and syntax highlighting
JSON Repair
Fix malformed, invalid, or broken JSON instantly. Repair truncated LLM output, missing commas, unquoted keys, and trailing commas in your browser
JSONL Formatter
Format JSON Lines (NDJSON) files and convert between JSON and JSONL. Validate each line and pretty-print NDJSON streams