XML Formatter
Format, beautify and syntax-check XML locally in your browser with line-and-column errors, Fetch URL and share links.
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
- Load your XML: Paste text, open or drop a local file, press Fetch URL for a public feed or press Sample.
- Pick the layout: Choose 2 spaces, 4 spaces or tabs, set attributes inline or one per line, or switch to Minify.
- 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.
- Export or continue: Copy output, download
formatted.xml(orminified.xmlin 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:
<?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>
<?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:
| Method | How to format | What to install | Error checking | Best for |
|---|---|---|---|---|
| CodeShack XML Formatter | Paste XML, open a file or Fetch URL | Nothing (runs in your browser) | XML 1.0 and namespaces, with line and column | Quick private checks and one-off files |
| Notepad++ | Plugins > XML Tools > Pretty print | The XML Tools plugin | Syntax check plus XSD and DTD validation | Windows users editing locally in Notepad++ |
| Visual Studio Code | Format Document (Shift+Alt+F on Windows, Shift+Option+F on macOS) | An XML extension such as XML by Red Hat | Syntax errors plus XSD and DTD validation | XML files inside a code project |
| xmllint | xmllint --format file.xml | libxml2 | Well-formedness plus XSD with --schema | Scripts, CI pipelines and huge files |
| Python | ElementTree.indent() | Built in (Python 3.9+) | Parser stops at the first syntax error | Formatting inside a Python script |
Common XML syntax mistakes
- A bare ampersand: Text like
AT&Ttriggers "A bare & must be written as &" because&always starts a reference. WriteAT&Tinstead. - HTML entities in XML:
and©belong to HTML, not XML, causing "The entity is not defined". Use numeric references such as or©. - 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.xmlwith 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.xmlfiles, WSDL specs and .NET.configfiles 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.























