📄 XML Formatter/Validator - Format and validate XML

📄
Characters: {{ xmlInput.length }}
⚙️
📏
⚡
{{ result.isValid ?'✅' :'❌' }}
{{ result.isValid ?'XML is valid and well-formed' :'XML contains errors' }}
🚨
{{ error }}
⚠️
{{ warning }}
📤
{{ result.formatted }}
Characters: {{ result.stats.formattedSize }}
📊
Elements:
{{ result.stats.elements }}
Attributes:
{{ result.stats.attributes }}
Text Nodes:
{{ result.stats.textNodes }}
Comments:
{{ result.stats.comments }}
💾
Original: {{ result.stats.originalSize }} chars (~{{ Math.round(result.stats.originalSize / 1024 * 100) / 100 }} KB)
Formatted: {{ result.stats.formattedSize }} chars (~{{ Math.round(result.stats.formattedSize / 1024 * 100) / 100 }} KB)
{{ result.stats.formattedSize > result.stats.originalSize ?'Increase:' :'Decrease:' }} {{ Math.abs(result.stats.originalSize - result.stats.formattedSize) }} chars
💾
⚠️ {{ error }}

ℹ️ About XML Formatter

XML (Extensible Markup Language) is a tagged document format for data interchange, configuration files, feeds, SOAP payloads, SVG metadata, build files, and application manifests. This online XML formatter pretty-prints nested elements, normalizes indentation, reports common syntax problems, and helps turn dense one-line XML into a structure that is easier to review.

The formatter follows the core XML ideas defined by the W3C XML 1.0 Recommendation: one document element, matching start and end tags, quoted attributes, character data, comments, processing instructions, CDATA sections, and optional XML declarations. Namespace-heavy documents can be checked against the naming model described in Namespaces in XML 1.0, while schema validation concepts are covered by W3C XML Schema Structures and XML Schema Datatypes.

  • Pretty print XML: expand compact XML into readable, consistently indented parent and child elements.
  • Validate XML syntax: catch mismatched closing tags, unclosed elements, missing roots, and malformed attribute assignments before using the document in another system.
  • Normalize generated output: clean XML returned by APIs, CI logs, CMS exports, RSS/Atom feeds, sitemap files, and configuration snippets.
  • Review structure: count elements, attributes, text nodes, and comments so large documents are easier to inspect.
  • Prepare safe examples: remove comments, sort attributes, or add an XML declaration when sharing a reduced reproduction.

Example input:

<order id="A100"><item sku="usb-c">Cable</item><total currency="USD">12.99</total></order>

Formatted output:

<order id="A100">
  <item sku="usb-c">Cable</item>
  <total currency="USD">12.99</total>
</order>

Parser and security limits: formatting is not the same as full validation. This page is designed for well-formedness and structure checks; it does not prove that a document satisfies a DTD, XSD, business rule, digital signature, or application-specific contract. Treat untrusted XML carefully because entity expansion, external entities, and parser configuration can create XXE and denial-of-service risks in server-side systems; see the OWASP XML External Entity Prevention Cheat Sheet before accepting XML uploads or enabling external entity resolution.

The interactive formatter runs in the browser for quick inspection. If you use the API endpoint or paste production payloads, remove secrets, tokens, customer data, and private identifiers first.

API Usage Example:

POST /api/tools/webdev/xml-formatter
Content-Type: application/json

{
    "xml": "<?xml version=\"1.0\"?><root><item id=\"1\">Value</item></root>",
    "format": true,
    "validate": true,
    "indentSize": 2,
    "indentType": "spaces",
    "removeComments": false,
    "sortAttributes": false,
    "addDeclaration": false
}
Ready