XML Formatter & Validator
Format, validate, and analyze XML documents with comprehensive options
Input & Settings
Formatted XML
Formatted XML will appear here
Analysis & Stats
Validation statistics will appear here
• Well-formed: Proper tag nesting and closing
• Valid: Conforms to DTD/Schema rules
• Case-sensitive: Tags and attributes
• Single root: One top-level element
XML Examples & Use Cases
Simple Structure
Basic XML with elements and text content.
<person>\n <name>John Doe</name>\n <age>30</age>\n <active>true</active>\n</person>With Attributes
XML elements with attributes for metadata.
<book id="123" category="fiction">\n <title lang="en">Sample Book</title>\n <author nationality="US">John Author</author>\n</book>Details
This tool helps you format and validate XML (Extensible Markup Language) documents. XML is widely used for storing and transporting data, especially in configuration files, web services (SOAP), and data exchange between systems. The formatter makes your XML human-readable with proper indentation, while the validator checks for well-formedness and can validate against XML schemas.
Examples
Basic XML Formatting
<!-- Before formatting -->
<root><element attribute="value">Text</element><element>More text with <child>nested element</child></element></root>
<!-- After formatting -->
<root>
<element attribute="value">Text</element>
<element>
More text with
<child>nested element</child>
</element>
</root>Transforms a compact, hard-to-read XML document into a properly indented format with clear hierarchical structure.
XML Validation
<!-- Invalid XML (Missing closing tag) -->
<person>
<name>John Doe</name>
<age>30</age>
<email>john@example.com
</person>
<!-- Error Message -->
Error at line 5: Element 'email' is not closedValidation detects common XML errors such as missing closing tags, invalid nesting, or malformed syntax.
XML with Namespaces
<!-- Before formatting -->
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"><soap:Header><auth xmlns="http://example.org/auth"><username>user</username><password>pass</password></auth></soap:Header><soap:Body><m:GetStockPrice xmlns:m="http://example.org/stock"><m:StockName>IBM</m:StockName></m:GetStockPrice></soap:Body></soap:Envelope>
<!-- After formatting -->
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope/">
<soap:Header>
<auth xmlns="http://example.org/auth">
<username>user</username>
<password>pass</password>
</auth>
</soap:Header>
<soap:Body>
<m:GetStockPrice xmlns:m="http://example.org/stock">
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>Formats complex XML with namespaces, common in SOAP web services and enterprise applications.
Examples
Format a simple person document
<person><name>John Doe</name><age>30</age><active>true</active></person><person>
<name>John Doe</name>
<age>30</age>
<active>true</active>
</person>
With the default two-space indentation, each child element is rebuilt on its own line and the result ends with a newline.
Format elements with attributes
<book id="123" category="fiction"><title lang="en">The Great Gatsby</title><year>1925</year></book><book id="123" category="fiction">
<title lang="en">The Great Gatsby</title>
<year>1925</year>
</book>
Attributes are retained while nested elements are expanded using the configured indentation.
About this tool
The XML Formatter & Validator parses XML with fast-xml-parser and rebuilds it as indented XML. The default configuration keeps attributes, converts recognizable tag and attribute values, trims surrounding text whitespace, and formats output with two spaces per level; the indent slider supports one through eight spaces.
Alongside the formatted document, the tool reports whether parsing succeeded, counts parsed element keys and attributes, records the source line count and processing time, and warns about a likely unescaped ampersand or content before the root element. You can also validate without producing formatted output.
Input can be pasted, restored from saved tool input, loaded from the built-in samples, or uploaded from an .xml or .txt file. Successful output can be copied or downloaded as an XML file. The formatter rebuilds a parsed object rather than preserving the source byte-for-byte, so lexical details such as original whitespace may change.
How to use
Load XML
Paste XML, upload an .xml or .txt file, or choose one of the Simple, Attributes, Nested, or CDATA samples.
Choose effective formatting options
Set the indent width and decide whether text values should preserve surrounding whitespace or whether empty nodes should be emitted in compact form.
Format or validate
Click Format & Validate to rebuild indented XML, or Validate Only to inspect parsing and statistics without creating output.
Review and export
Check errors, warnings, element and attribute counts, then copy the output or download it as an .xml file.
Use cases
Review a compact API payload
Expand a one-line XML response into an indented document that is easier to inspect during integration debugging.
Check basic well-formedness
Run Validate Only to catch parser errors and review warnings before passing XML to another system.
Inspect document structure
Use the element, attribute, line, error, and warning counts for a quick overview of an unfamiliar XML file.
Prepare readable configuration
Format XML-based configuration before review, then copy or download the rebuilt document.
Common mistakes
Mistake:Treating a successful parse as validation against a DTD or XML Schema.
Fix:Use the result as a well-formedness check only; the component does not load or enforce a DTD or XSD.
Mistake:Expecting the formatter to preserve every lexical detail.
Fix:Keep the original file when comments, CDATA boundaries, entity spelling, attribute order, or exact whitespace must remain byte-for-byte unchanged.
Mistake:Assuming every visible switch changes the parser or builder.
Fix:Only rely on behavior visible in the result. In the current component, preserve-comments, sort-attributes, and self-closing-tags state is not passed into the parser or builder options.
Mistake:Reading the element statistic as a standards-level node count.
Fix:Treat it as the component's recursive object-key count; repeated arrays and parser conversions can make it differ from a DOM element count.
Frequently asked questions
References & standards
Related tools
Base64 Toolbox
Professional Base64 workspace for text, files and images with Base64URL, MIME, Data URI, strict validation, image preview and ready-to-use snippets.
CSV to Chart
Paste or upload CSV data and generate bar, line, pie, or doughnut charts. Export as PNG.
CSV to JSON Converter
Paste CSV data and convert it to pretty-printed JSON instantly — supports custom delimiters, header row toggling, and value trimming.
cURL to Code Converter
Convert cURL commands to code snippets in multiple languages. Parse cURL and generate JavaScript, Python, PHP, and more.
Diff Checker
Compare two text blocks and highlight differences side-by-side
GraphQL Formatter & Validator
Format, validate and beautify GraphQL queries with syntax highlighting