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
DOMParseris 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.
xmllint or SAXParser with your schema file.
XML vs JSON vs YAML — when to pick which
| Feature | XML | JSON | YAML |
|---|---|---|---|
| Comments | Yes <!-- ... --> | No | Yes |
| Schema validation | XSD, DTD, RELAX NG (excellent) | JSON Schema (good) | Reuses JSON Schema |
| Namespaces | Yes (xmlns) | No | No |
| Mixed content (text + tags) | Yes | No | No |
| Attributes vs elements | Both (creates ambiguity) | Just keys | Just keys |
| Verbosity | Highest (closing tags double size) | Medium | Lowest |
| Parser maturity | Decades — every language | Universal | Newer, some quirks |
| Best for | Document-oriented data, regulated industries, SOAP, feeds, configs needing validation | API payloads, JS-heavy stacks | Human-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
<?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
<?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)
<?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
<?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
<?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:
<!-- 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)
// 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)
import format from 'xml-formatter';
const formatted = format(xmlString, {
indentation: ' ',
collapseContent: true,
lineSeparator: '\n',
});
Python (lxml or built-in xml.dom.minidom)
# 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)
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($xmlString);
echo $dom->saveXML();
Java (Transformer API)
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)
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)
# 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
// 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:
| Tool | Browser-only | Validation engine | Format support | Min/Beautify both | Cost |
|---|---|---|---|---|---|
| FreeDevTool XML Formatter | Yes (DOMParser) | Native browser, line-numbered errors | SOAP, RSS, Atom, sitemap, POM, generic | Yes | Free |
| xmlformatter.org | Yes | Custom JS, partial errors | Generic | Yes | Free, ad-funded |
| codebeautify.org/xmlviewer | Server-side | Server XML parser | Generic + tree view | Yes | Free, ad-heavy |
| xmlgrid.net | Server-side | Java-side parser | Generic + grid view | Yes | Free, ad-funded |
xmllint (CLI) | Local install | libxml2 | Full XML 1.0/1.1, XSD, RelaxNG | Both via flags | Free, OSS |
| VS Code XML extension (Red Hat) | Local IDE | LemMinX (Eclipse) | Full + XSD validation | Format-on-save | Free |
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?
| Format | Best for | Strict typing | Comments | Schema language | 2026 status |
|---|---|---|---|---|---|
| XML | SOAP, RSS, Maven, Android, document-centric | Via XSD | Yes (<!-- -->) | XSD, DTD, RelaxNG | Legacy + niche (still huge in enterprise SOAP/Java) |
| JSON | REST APIs, web app data | Limited (string/number/bool) | No | JSON Schema | Default for web in 2026 |
| YAML | Config files (Kubernetes, Docker Compose, GitHub Actions) | Limited | Yes (#) | JSON Schema (subset) | Default for DevOps configs |
| TOML | Config files (Cargo, pyproject, Hugo) | Yes (typed) | Yes (#) | None standardized | Growing 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
- 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.
- 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.
- 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.
- 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 --schemain 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 setFEATURE_SECURE_PROCESSING, in PHP avoidlibxml_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<. - Mind whitespace handling. XML preserves whitespace inside elements by default. Use
xml:space="preserve"for content that requires exact formatting (like code samples).