How to Format and Validate XML
Paste an XML document or open a local XML-related file. The browser parser checks the source immediately. Valid documents can be beautified with two- or four-space indentation or minified for a compact output. Review the result, then copy it or download a new XML file.
1. Add XML
Paste source or open XML, SVG, XHTML, XSD, RSS, or Atom text.
2. Review validation
Fix the parser message and reported location if the document is not well-formed.
3. Export the result
Choose beautify or minify, then copy the output or download an XML file.
What Well-Formed XML Means
A well-formed XML document has exactly one root element, correctly nested tags, matching closing tags, quoted attribute values, and valid names. Entity references and declarations must also be syntactically valid. Namespace prefixes must be declared where they are used.
Well-formedness is different from schema validity. An order document can be perfectly well-formed while still missing a field required by its XSD. This tool checks XML syntax only and labels that scope clearly.
Beautifying and Minifying XML Safely
Beautifying adds line breaks and indentation around element-only structures. Mixed-content elements can contain meaningful text before, between, or after child elements, so the formatter keeps those elements compact rather than inserting text-changing whitespace. Regions marked with xml:space="preserve" are also serialized without layout changes.
Minifying removes indentation-only nodes where the structure makes that safe. It does not shorten element names, attributes, text, or CDATA content. Specialized applications may assign their own meaning to whitespace, so compare the output when working with unfamiliar XML vocabularies.
Common XML Syntax Errors
- Mismatched tags
An opening <item> must close with </item>, and nested elements must close in reverse order.
- Unquoted attributes
XML requires quoted attribute values, such as id="42" rather than id=42.
- Unescaped characters
Literal ampersands in text must normally be written as &amp; unless they begin a valid entity.
- Missing namespace declarations
A prefixed name such as media:title needs a matching xmlns:media declaration in scope.
XML Standards and Browser References
For the formal syntax, read the W3C XML specification. For the browser parsing interface used by this type of client-side tool, see the MDN DOMParser reference. External references open in a new tab.
Private, Browser-Based XML Processing
Validation, formatting, statistics, copying, and file creation run locally in the browser. The XML does not need to be uploaded to calculate the result. Refreshing the page clears the current workspace.
Continue Your Developer Workflow
Format API payloads with the JSON Formatter & Validator, convert configuration data using the YAML ↔ JSON Converter, transform tabular data using the CSV ↔ JSON Converter, or encode URL components with the URL Encoder & Decoder.