Back Formatting

XML Formatter, Validator & Beautifier Online

Format, beautify, validate, and minify XML documents. Pretty-prints SOAP envelopes, RSS feeds, Atom feeds, sitemap.xml, configuration files, and any well-formed XML. Uses the browser's native DOMParser for accurate XML 1.0 well-formedness validation. Your XML data — including ones with sensitive content — never leaves your machine.

Last updated: April 2026
0 lines, 0 chars
0 lines, 0 chars
Copied!

What is XML and why is it still everywhere?

XML (eXtensible Markup Language) is a structured text format defined in W3C XML 1.0. Designed in 1998 to be both human-readable and machine-parseable, XML became the dominant data interchange format of the early 2000s. While JSON has overtaken it for new APIs, XML remains the backbone of mature ecosystems: SOAP web services, RSS & Atom feeds, sitemaps, OpenDocument and Microsoft Office files (under the hood), Android resources (AndroidManifest.xml, layouts, strings), Java/Maven (pom.xml), Spring configuration, SVG vector graphics, MathML, EPUB e-books, RFID and HL7 healthcare data, and EDI commerce protocols.

Two reasons XML survived JSON's rise:

  • Schemas and validation are world-class. XML Schema (XSD), DTD, RELAX NG, and Schematron provide stricter validation than JSON Schema. Industries with regulatory requirements (healthcare, finance, government) chose XML and rarely migrate.
  • Mixed content + namespaces. XML elegantly mixes text and tags (<p>Hello <b>world</b>!</p>) and supports namespaces for combining vocabularies (e.g. SOAP envelope wrapping a domain-specific payload). JSON has no equivalent.

If you're consuming a SOAP API, debugging an Android layout, validating an RSS feed, or inspecting an SVG file, you're working with XML. A formatter turns the typical single-line, attribute-heavy XML into something a human can navigate.

How XML formatting works

XML formatting follows the same compiler pipeline as SQL or JSON formatting:

  • 1. Parse the input into a DOM (Document Object Model). The browser's built-in DOMParser is robust, fast, and handles all of XML 1.0 — well-formedness checks, entity resolution, CDATA sections, processing instructions, namespaces.
  • 2. Validate well-formedness. Every open tag must have a close tag (or be self-closing), elements must nest properly, attribute values must be quoted, names are case-sensitive. Errors are reported with line/column.
  • 3. Pretty-print by walking the DOM, emitting open/close tags with chosen indentation, preserving CDATA, comments, and processing instructions.

This tool runs all three stages in your browser — your XML never reaches a server, which matters when formatting SOAP payloads with API keys, healthcare records (HL7), or proprietary configuration.

Well-formed vs valid: "well-formed" means the XML follows the grammar rules (matching tags, quoted attributes, etc.). "Valid" means it additionally conforms to a schema (DTD, XSD, RELAX NG). This formatter checks well-formedness only — for schema validation, use xmllint or SAXParser with your schema file.

XML vs JSON vs YAML — when to pick which

FeatureXMLJSONYAML
CommentsYes <!-- ... -->NoYes
Schema validationXSD, DTD, RELAX NG (excellent)JSON Schema (good)Reuses JSON Schema
NamespacesYes (xmlns)NoNo
Mixed content (text + tags)YesNoNo
Attributes vs elementsBoth (creates ambiguity)Just keysJust keys
VerbosityHighest (closing tags double size)MediumLowest
Parser maturityDecades — every languageUniversalNewer, some quirks
Best forDocument-oriented data, regulated industries, SOAP, feeds, configs needing validationAPI payloads, JS-heavy stacksHuman-edited config (k8s, CI)

For new public APIs in 2026, JSON wins by default. Choose XML when you have legacy compatibility constraints, when you need namespaces (SOAP), or when you're producing/consuming an established XML format (RSS, Atom, sitemap, SVG).

Common XML formats you'll encounter

SOAP envelopes

soap
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <auth:Credentials xmlns:auth="urn:auth">
      <auth:Token>abc123</auth:Token>
    </auth:Credentials>
  </soap:Header>
  <soap:Body>
    <ns:GetUserRequest xmlns:ns="urn:user">
      <ns:Id>42</ns:Id>
    </ns:GetUserRequest>
  </soap:Body>
</soap:Envelope>

RSS feed

rss
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>FreeDevTool Blog</title>
    <link>https://freedevtool.org/blog</link>
    <description>Developer tools and tutorials</description>
    <item>
      <title>What is URL encoding?</title>
      <link>https://freedevtool.org/blog/url-encoding</link>
      <pubDate>Mon, 30 Apr 2026 12:00:00 GMT</pubDate>
    </item>
  </channel>
</rss>

Sitemap (sitemap.xml)

sitemap
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://freedevtool.org/</loc>
    <lastmod>2026-04-30</lastmod>
    <changefreq>weekly</changefreq>
    <priority>1.0</priority>
  </url>
</urlset>

Maven pom.xml

maven
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>myapp</artifactId>
  <version>1.0.0</version>
  <dependencies>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>6.1.0</version>
    </dependency>
  </dependencies>
</project>

Android layout XML

android
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:id="@+id/title"
        android:text="Hello, world!"
        android:textSize="20sp" />
</LinearLayout>

XML namespaces — why they exist and how they work

Namespaces let you mix vocabularies in a single document without name collisions. <title> in HTML, RSS, and Atom all mean different things — namespaces disambiguate them. The syntax is the xmlns attribute:

xml
<!-- Default namespace — all unprefixed children belong to it -->
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>...</url>
</urlset>

<!-- Prefixed namespace — explicit on every element -->
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>...</soap:Body>
</soap:Envelope>

<!-- Multiple namespaces in one document -->
<feed xmlns="http://www.w3.org/2005/Atom"
      xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>My Blog</title>
  <dc:creator>Anees</dc:creator>
</feed>

Namespaces are URLs but they don't need to resolve to anything — they're just unique identifiers. This is why http://www.w3.org/1999/xhtml works as the XHTML namespace even though there's no document at that URL.

XML formatting in 8 toolchains

Browser (DOMParser + XMLSerializer)

javascript
// Parse + validate
const doc = new DOMParser().parseFromString(xmlString, 'application/xml');
const err = doc.querySelector('parsererror');
if (err) console.error('Invalid XML:', err.textContent);

// Pretty-print (manual indentation since XMLSerializer doesn't indent)
function prettyXml(xml) {
  const reg = /(>)(<)(\/*)/g;
  let formatted = xml.replace(reg, '$1\r\n$2$3');
  let pad = 0;
  return formatted.split('\r\n').map(node => {
    if (node.match(/.+<\/\w[^>]*>$/)) {} // open + close on same line
    else if (node.match(/^<\/\w/)) pad -= 1;
    else if (node.match(/^<\w[^>]*[^\/]>.*$/)) pad += 1;
    return '  '.repeat(pad - (node.match(/^<\/\w/) ? 0 : 0)) + node;
  }).join('\n');
}

Node.js (xml-formatter)

node.js
import format from 'xml-formatter';

const formatted = format(xmlString, {
  indentation: '  ',
  collapseContent: true,
  lineSeparator: '\n',
});

Python (lxml or built-in xml.dom.minidom)

python
# lxml — most popular, fastest
from lxml import etree
parser = etree.XMLParser(remove_blank_text=True)
root = etree.fromstring(xml_bytes, parser)
print(etree.tostring(root, pretty_print=True).decode())

# Built-in alternative
from xml.dom.minidom import parseString
dom = parseString(xml_string)
print(dom.toprettyxml(indent="  "))

PHP (DOMDocument)

php
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($xmlString);
echo $dom->saveXML();

Java (Transformer API)

java
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

DOMSource source = new DOMSource(document);
StringWriter writer = new StringWriter();
transformer.transform(source, new StreamResult(writer));
String formatted = writer.toString();

Go (encoding/xml)

go
import "encoding/xml"

// Parse, then re-marshal with indentation
type Note struct {
    XMLName xml.Name `xml:"note"`
    To      string   `xml:"to"`
    From    string   `xml:"from"`
    Body    string   `xml:"body"`
}

var n Note
xml.Unmarshal([]byte(xmlData), &n)
out, _ := xml.MarshalIndent(n, "", "  ")

Bash (xmllint)

bash
# xmllint is part of libxml2 — pre-installed on most Linux/macOS

# Pretty-print
xmllint --format file.xml

# Pretty-print with custom indent
XMLLINT_INDENT='    ' xmllint --format file.xml

# Validate against a schema (XSD)
xmllint --noout --schema schema.xsd file.xml

# Validate against a DTD
xmllint --noout --valid file.xml

# Convert to canonical form (for signature comparison)
xmllint --c14n file.xml

VS Code: XML extension

vscode
// Install "XML" extension by Red Hat (uses LemMinX language server)
// Right-click → "Format Document" or Shift+Alt+F

// Or use Prettier with @prettier/plugin-xml:
npx prettier --plugin=@prettier/plugin-xml file.xml

// Settings.json:
{
  "[xml]": { "editor.defaultFormatter": "redhat.vscode-xml" }
}

Best XML formatter for 2026 — what to compare

Search results for "xml formatter online", "xml beautifier", and "xml pretty print" return dozens of single-purpose web tools and CLI utilities. Three things separate the good from the noise: native browser validation (DOMParser correctly reports line-numbered syntax errors) versus regex-based fakes that miss real bugs, support for the formats developers actually paste (SOAP, RSS, Maven POM, Android layouts), and whether the tool sends documents to a server. Here is how the most-used XML tools compare in 2026:

ToolBrowser-onlyValidation engineFormat supportMin/Beautify bothCost
FreeDevTool XML FormatterYes (DOMParser)Native browser, line-numbered errorsSOAP, RSS, Atom, sitemap, POM, genericYesFree
xmlformatter.orgYesCustom JS, partial errorsGenericYesFree, ad-funded
codebeautify.org/xmlviewerServer-sideServer XML parserGeneric + tree viewYesFree, ad-heavy
xmlgrid.netServer-sideJava-side parserGeneric + grid viewYesFree, ad-funded
xmllint (CLI)Local installlibxml2Full XML 1.0/1.1, XSD, RelaxNGBoth via flagsFree, OSS
VS Code XML extension (Red Hat)Local IDELemMinX (Eclipse)Full + XSD validationFormat-on-saveFree

How do I format and validate an XML file online without uploading it?

Paste the XML into the input pane on this page. The browser's DOMParser parses the document locally — nothing uploads. DOMParser is the same NIST-grade XML implementation that powers the browser's RSS reader, sitemap consumer, and SOAP/WS-* libraries; validation errors include line and column numbers. Avoid online formatters that require an upload (look for a "Choose file" button or POST request on Network tab) — these often log submitted XML, which is a confidentiality risk for SOAP envelopes containing tokens or sitemap files exposing unannounced URLs.

What's the difference between XML, JSON, and YAML for data interchange?

FormatBest forStrict typingCommentsSchema language2026 status
XMLSOAP, RSS, Maven, Android, document-centricVia XSDYes (<!-- -->)XSD, DTD, RelaxNGLegacy + niche (still huge in enterprise SOAP/Java)
JSONREST APIs, web app dataLimited (string/number/bool)NoJSON SchemaDefault for web in 2026
YAMLConfig files (Kubernetes, Docker Compose, GitHub Actions)LimitedYes (#)JSON Schema (subset)Default for DevOps configs
TOMLConfig files (Cargo, pyproject, Hugo)Yes (typed)Yes (#)None standardizedGrowing in Rust/Python ecosystem

Decision rule: REST API → JSON. Kubernetes / CI config → YAML. SOAP / Java enterprise / Maven / Android → XML. New Rust/Python project config → TOML. Use this XML Formatter, JSON Formatter, and YAML to JSON together when shuttling data between systems.

XML formatter alternative to codebeautify.org — 4 reasons developers switched

  1. Browser-only, no server upload. codebeautify and xmlgrid POST your XML to their servers. SOAP envelopes, sitemaps, and config files often contain sensitive paths or auth tokens — keep them in-browser.
  2. Native DOMParser validation. Custom-JS validators catch ~70% of well-formedness errors. The browser's DOMParser catches 100% with line-numbered errors that match what your real production parser will throw.
  3. Format-aware previews. SOAP envelope, RSS feed, Atom feed, sitemap, and POM templates surface in the example dropdown — paste any of those and the formatter applies appropriate namespace handling.
  4. No ads, no login wall, no rate limit. Tools indexed for "xml formatter online" almost universally inject ads or gate features (XSD validation, large-file paste) behind login. This page has neither.

Pair the XML formatter with the JSON Formatter for REST APIs, the YAML to JSON for Kubernetes manifests, the URL Encoder for percent-encoding inside XML attributes, and the Encoding Tools hub for the broader transform toolkit.

XML best practices

  • Always include the XML declaration. <?xml version="1.0" encoding="UTF-8"?> at the top tells parsers the encoding. Without it, parsers fall back to platform default which can corrupt non-ASCII characters.
  • Use UTF-8 encoding. The XML 1.0 spec requires UTF-8 or UTF-16 support. Stick with UTF-8 — it's universal.
  • Validate against a schema in CI. XSD/RELAX NG validation catches typos and structural errors before deployment. Run xmllint --schema in your build pipeline.
  • Beware of XXE (XML External Entity) attacks. Allowing external entity expansion is a security hole — use a hardened parser. In Python defusedxml, in Java set FEATURE_SECURE_PROCESSING, in PHP avoid libxml_disable_entity_loader(false).
  • Don't parse XML with regex. XML is context-free; regex isn't. Use a real parser (DOMParser, lxml, etree, etc.). The famous Stack Overflow answer is a meme for a reason.
  • Prefer attributes for metadata, elements for content. The convention: <item id="42">Title</item> not <item><id>42</id><title>Title</title></item> when the data is simple.
  • Use CDATA for embedded markup. If you need to include HTML or code in XML, wrap it in <![CDATA[...]]> instead of escaping every < as &lt;.
  • Mind whitespace handling. XML preserves whitespace inside elements by default. Use xml:space="preserve" for content that requires exact formatting (like code samples).

Frequently Asked Questions

What is XML formatting and why is it important?
XML formatting adds consistent indentation and line breaks to XML documents, making deeply nested structures human-readable. Unformatted XML from APIs, SOAP web services, RSS feeds, or configuration files is often compressed into a single line. Proper formatting is essential for debugging XML parsing errors, reviewing configuration files like pom.xml, web.xml, and AndroidManifest.xml, and understanding complex document structures.
How do I validate XML syntax?
Well-formed XML must follow these rules: every opening tag needs a matching closing tag, tags must be properly nested without overlapping, attribute values must be enclosed in quotes, element names are case-sensitive, and there must be exactly one root element. Self-closing tags like <br/> are also valid. This tool uses the browser's built-in DOMParser to validate XML and reports any syntax errors with descriptions.
What is the difference between XML and HTML?
XML is strict and extensible — you define your own tag names, all tags must be explicitly closed, attributes must be quoted, and element names are case-sensitive. HTML is more lenient — it has predefined tags, browsers auto-close certain elements, and it's case-insensitive. XML is used for data transport (SOAP APIs, RSS feeds, config files, SVG), while HTML is for rendering web pages in browsers.

Browse all 50 free developer tools

All tools run in your browser, no signup required, nothing sent to a server.