XML Formatter
Format, validate, and minify XML documents with proper indentation.
What this tool does
XML (Extensible Markup Language) remains the lingua franca of enterprise data exchange, SOAP APIs, configuration files (Maven, Ant, Spring), and document formats like DOCX and SVG. Despite JSON's popularity for new APIs, XML's support for namespaces, schemas, and mixed content makes it irreplaceable for certain domains. This tool formats, validates, and minifies XML with proper namespace awareness.
The beautifier preserves the original document structure including processing instructions, CDATA sections, comments, and DOCTYPE declarations. It correctly handles self-closing tags, empty elements, and attributes containing special characters. Validation surfaces parse errors with line and column positions to help you quickly identify malformed markup.
Usage Example
<!-- Input -->
<catalog xmlns="urn:books"><book id="1" available="true"><title>Pride and Prejudice</title><author>Austen</author></book><book id="2" available="false"><title>1984</title><author>Orwell</author></book></catalog>
<!-- Formatted -->
<catalog xmlns="urn:books">
<book id="1" available="true">
<title>Pride and Prejudice</title>
<author>Austen</author>
</book>
<book id="2" available="false">
<title>1984</title>
<author>Orwell</author>
</book>
</catalog>Common Edge Cases
- Self-closing tags like <br/> and <img src="..."/> are preserved as-is, while elements with only whitespace children are converted to self-closing form by the minifier.
- CDATA sections (<![CDATA[...]]>) prevent the parser from interpreting content as markup, which is essential for embedding XML or HTML inside XML.
- Namespace prefixes (xmlns:prefix="...") must be declared on the element where they are used or an ancestor; the formatter preserves them in their original positions.
- Attribute values containing <, >, or & are invalid and must be escaped as <, >, & or wrapped in CDATA.
- Processing instructions like <?xml-stylesheet href="style.xsl" type="text/xsl"?> are preserved but must appear before the root element.
FAQ
- Can it validate against an XSD schema?
- No. This tool checks well-formedness (syntactic validity), not schema validity. For XSD validation, use a tool like xmllint or a language-specific library.
- Does it support XSLT and XPath?
- No. This tool only formats XML. For transformations and queries, you need an XSLT processor (Saxon, libxslt) or XPath engine.
- What is the difference between XML and HTML formatting?
- HTML has predefined tags and lenient parsing, while XML is strict and case-sensitive. Always use an HTML formatter for HTML, even though the syntax looks similar.