How to Format XML Online
Format and pretty-print XML documents instantly with our free XML Formatter. Adds indentation, fixes structure, and highlights syntax.
Steps
Paste your XML
Copy your raw or minified XML and paste it into the input area. The tool accepts any valid XML including documents with declarations (<?xml version='1.0'?>), namespaces, attributes, CDATA sections, and comments.
Set indentation preference
Choose 2-space, 4-space, or tab indentation. The default 2-space indentation is most common and keeps nested XML manageable even with deeply structured documents.
Click Format
Press Format to parse and reformat the XML. The tool will detect and report any well-formedness errors — unclosed tags, mismatched tags, invalid attribute syntax — before outputting the formatted version.
Review the formatted output
The output shows your XML with consistent indentation and syntax highlighting. Attributes, element names, values, and comments are colour-coded for easy reading. Check that all elements are properly nested.
Copy or validate
Copy the formatted XML to your clipboard. Optionally use the Validate button to check the XML against its schema (XSD) if one is provided, confirming that it is not just well-formed but also valid.
XML vs JSON: When to Use Each
XML and JSON both represent structured data but have different strengths. JSON is more compact, easier to read for most people, natively supported by JavaScript, and has become the default for web APIs since around 2010. XML has several advantages over JSON: it supports mixed content (text with embedded elements), has a mature ecosystem of standards (XPath, XSLT, XSD, SAX/DOM parsing), supports comments, has better namespace handling for combining vocabularies, and is the required format for SOAP web services, RSS/Atom feeds, SVG images, Microsoft Office formats (DOCX, XLSX), Android layouts, and Maven project files. If you are working with an existing XML system, understanding XML formatting and validation is essential.
Common XML Formats You Will Encounter
XML appears in many domain-specific formats. SOAP: web service messages use XML for both request and response envelopes. RSS and Atom: syndication feed formats for blogs and news. SVG: scalable vector graphics use XML to describe paths, shapes, and transforms. XHTML: an XML-serialised version of HTML. Android resources: layout files, strings, and manifests are all XML. Maven POM: project configuration for Java build tools. Log4j/Logback: logging configuration files. Spring: application context and bean definition files. DocBook and DITA: technical documentation formats. Knowing the formatter works for all these formats lets you quickly inspect and debug any XML you encounter.
Frequently Asked Questions
Well-formed XML follows the basic syntax rules: every opening tag has a closing tag, elements are properly nested (no overlapping), attribute values are quoted, and there is a single root element. Valid XML additionally conforms to a document type definition (DTD) or XML Schema (XSD) that defines the allowed elements, attributes, and structure. An XML document can be well-formed but not valid if it uses element names not defined in the schema.
The browser-based formatter handles XML files up to several megabytes without issue on modern devices. For very large files (hundreds of megabytes or gigabytes), a command-line tool like xmllint (Linux/Mac) or PowerShell's Xml type (Windows) will perform better: xmllint --format file.xml > formatted.xml
In most XML use cases, formatting does not affect data semantics because parsers ignore insignificant whitespace between elements. However, in mixed content (elements that contain both child elements and text), added whitespace can become part of the text content. For XML used in SOAP web services or specific data interchange formats, check whether whitespace handling matters before formatting.
On Linux and Mac: xmllint --format input.xml > output.xml. On Windows with PowerShell: [xml](Get-Content input.xml) | Format-Xml | Set-Content output.xml. In Python: python3 -c "import xml.dom.minidom; print(xml.dom.minidom.parse('input.xml').toprettyxml(indent=' '))". The online formatter is faster for one-off formatting without switching to a terminal.