Mode
Paste XML, open a file or press Sample. The check runs as you type and names the line and column of any error.
Send the result to: XML Viewer XML to JSON Converter

What is an XML formatter?

An XML formatter (also called an XML beautifier or pretty printer) turns compressed or messy XML into indented lines so nested elements and attributes are easy to read.

This free browser-based tool on CodeShack formats and validates XML syntax locally in JavaScript. Opened files automatically detect UTF-8, UTF-16 (with a BOM or <?xml ...?> declaration) and browser-supported encodings.

As you type, the parser checks XML 1.0 and XML Namespaces well-formedness. It flags undeclared prefixes, duplicate namespaced attributes and broken tags with exact line and column numbers plus a Go to line jump button.

Because the formatter builds a full document tree instead of using regular expressions, it preserves text values, mixed content, <![CDATA[...]]> sections, attribute values and xml:space="preserve" blocks (per section 2.10 of the W3C XML 1.0 specification). Line endings are normalized to LF.

How to format XML

  1. Load your XML: Paste text, open or drop a local file, press Fetch URL for a public feed or press Sample.
  2. Pick the layout: Choose 2 spaces, 4 spaces or tabs, set attributes inline or one per line, or switch to Minify.
  3. Review the status bar: Well-formed XML lists the root tag with element, attribute and depth counts (plus namespaces when present); errors show line and column with Go to line.
  4. Export or continue: Copy output, download formatted.xml (or minified.xml in Minify mode), press Share XML for a URL-hash link, or send the result to XML Viewer or XML to JSON Converter.

XML formatting example: before and after

This one-line XML order is formatted with the default 4-space indentation:

Input: one line of XML
<?xml version="1.0" encoding="UTF-8"?><order id="1042"><customer>Ada Park</customer><items><item sku="KB-01" qty="1">Mechanical keyboard</item><item sku="MS-07" qty="2">Wireless mouse</item></items><tracking xmlns="urn:example:ship">TRK-20931</tracking><note>Leave it at the <b>side</b> door.</note></order>
Output: formatted XML
<?xml version="1.0" encoding="UTF-8"?>
<order id="1042">
    <customer>Ada Park</customer>
    <items>
        <item sku="KB-01" qty="1">Mechanical keyboard</item>
        <item sku="MS-07" qty="2">Wireless mouse</item>
    </items>
    <tracking xmlns="urn:example:ship">TRK-20931</tracking>
    <note>Leave it at the <b>side</b> door.</note>
</order>

Notice that <tracking> stays on one line even though it declares a namespace, and <note> keeps its exact spacing because it mixes text with a <b> tag.

Many regex-based online formatters corrupt namespaced values like <m:Get xmlns:m="urn:x">1</m:Get> into multi-line output with extra tabs and newlines around 1. That changes the text node value and can break strict SOAP parsers, xs:integer checks or XML signatures.

Ways to format XML

You can format XML in a browser, a desktop code editor or from the command line:

Ways to format XML compared by setup and error checking
MethodHow to formatWhat to installError checkingBest for
CodeShack XML FormatterPaste XML, open a file or Fetch URLNothing (runs in your browser)XML 1.0 and namespaces, with line and columnQuick private checks and one-off files
Notepad++Plugins > XML Tools > Pretty printThe XML Tools pluginSyntax check plus XSD and DTD validationWindows users editing locally in Notepad++
Visual Studio CodeFormat Document (Shift+Alt+F on Windows, Shift+Option+F on macOS)An XML extension such as XML by Red HatSyntax errors plus XSD and DTD validationXML files inside a code project
xmllintxmllint --format file.xmllibxml2Well-formedness plus XSD with --schemaScripts, CI pipelines and huge files
PythonElementTree.indent()Built in (Python 3.9+)Parser stops at the first syntax errorFormatting inside a Python script

Common XML syntax mistakes

  • A bare ampersand: Text like AT&T triggers "A bare & must be written as &amp;" because & always starts a reference. Write AT&amp;T instead.
  • HTML entities in XML: &nbsp; and &copy; belong to HTML, not XML, causing "The entity &nbsp; is not defined". Use numeric references such as &#160; or &#169;.
  • Whitespace before the XML declaration: A blank line or space before <?xml version="1.0"?> breaks parsing because the declaration must begin at character 1.
  • Multiple root elements: Every XML document must have a single outer tag. Two sibling top-level tags cause "Extra content at the end of the document" in standard parsers.
  • Mismatched or case-sensitive tags: XML tag names are case-sensitive, so <Item>...</item> triggers an opening and ending tag mismatch error.
  • Unquoted attribute values: Unlike HTML, XML requires quotes around every attribute value (<item id="1">, never <item id=1>).

Common XML use cases

  • SOAP and API payloads: Indent nested envelopes to inspect fields without altering namespaced values.
  • Sitemaps and RSS feeds: Load a public feed or sitemap.xml with Fetch URL to catch broken tags or unescaped ampersands before publishing.
  • SVG images: Expand minified single-line SVG markup before editing paths or attributes by hand.
  • Config and build files: Clean up Android layouts, Maven pom.xml files, WSDL specs and .NET .config files for review.
  • cXML orders and diffs: Format deeply nested procurement files consistently before comparing two versions in Text Compare.

More XML tools

Browse large documents as a collapsible tree in the XML Viewer, convert data in the XML to JSON Converter, reorder tags in the XML Sorter or compress files in the dedicated XML Minifier.

Frequently Asked Questions

Is my XML uploaded to a server?

No. Pasted XML and opened local files are formatted and checked completely in your browser with JavaScript, so your data stays on your device.

The only server request happens if you use Fetch URL, which retrieves public URLs (up to 5 MB, 10-second cooldown) through our fetch proxy. Share XML packs snippets (under ~6 KB compressed) into the URL hash without storing them on a server.

What is the difference between well-formed and valid XML?

Well-formed XML obeys core XML 1.0 and Namespaces syntax rules, such as a single root element, properly nested tags and escaped entities. Valid XML is well-formed and also matches an external schema such as an XSD or DTD. This formatter checks well-formedness live as you type.

Does this tool validate XML against an XSD or DTD schema?

No. It checks XML 1.0 and XML Namespaces syntax only. For full XSD or DTD schema validation, use xmllint --schema, Visual Studio Code with the Red Hat XML extension or Notepad++ with XML Tools.

How large an XML file can I format in the browser?

Files up to several megabytes format smoothly in modern desktop browsers. For very large dumps (tens of megabytes or more), a command-line tool like xmllint --format is faster and uses less memory.