XML Formatter
Paste any XML — config files, SOAP envelopes, Android manifests, Maven POMs — and get back clean, beautified, indented output.
What is an XML formatter?
Unlike every formatter on this site that calls an external API service, this one runs directly in your Blazor Server circuit using System.Xml.Linq.XDocument — it parses your document and re-serialises it with consistent indentation and one element per line, making the hierarchical structure immediately visible. It also validates the XML as a side effect — if the markup is malformed (mismatched tags, missing quotes on attributes, unclosed elements) you get a precise error instead of the silent failures that often occur when copying XML between systems.
Why any DOCTYPE declaration — even a purely inline one — produces an error here
DTD processing is disabled with DtdProcessing.Prohibit and XmlResolver = null before the document is parsed (XmlFormatter.razor:86-88). Most people expect this to block only external entity resolution — the classic XXE attack where <!DOCTYPE foo [<!ENTITY ext SYSTEM "file:///etc/passwd">]> would cause the parser to fetch an external file. But DtdProcessing.Prohibit goes further: it throws on any <!DOCTYPE> declaration at all, including fully inline internal subsets with no external references. An XML document with a DOCTYPE that defines only local element declarations — nothing fetched, nothing dangerous — still fails to parse here, because the .NET XML reader rejects the DOCTYPE node itself before examining its content. This is the intentionally conservative setting. An internal DTD can still define entity expansions that reference other entities recursively (the "Billion Laughs" XML bomb attack), which makes even inline DTDs potentially dangerous to parse without limits. If your XML has a DOCTYPE you know is safe, remove the declaration before formatting — the structure and data will format identically without it.
XML vs JSON — when XML is still the right choice
JSON has largely replaced XML for new REST APIs, but XML remains dominant in several important domains:
- SOAP web services: Enterprise integrations, banking systems, and legacy APIs often use SOAP, which wraps requests and responses in XML envelopes
- Android development: AndroidManifest.xml, layout files, resource files, and Gradle build scripts use XML
- Java/Maven: pom.xml defines Maven project structure, dependencies, and build configuration
- .NET/MSBuild: .csproj, .sln (partially), NuGet .nuspec, and web.config files are XML
- Office documents: DOCX, XLSX, and PPTX files are ZIP archives containing XML
- RSS and Atom feeds: Syndication formats for blogs and news are XML
- SVG: Scalable vector graphics are XML documents
XML namespaces
Namespaces allow XML documents to combine elements from multiple vocabularies without name collisions. A namespace is declared with xmlns:prefix="URI" and then used as a prefix on element names: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">. The URI is just an identifier — it does not need to resolve to an actual document. The default namespace (xmlns="URI") applies to all unprefixed elements in its scope. The formatter preserves namespace declarations and prefixes exactly as they appear in the input.
Well-formed vs valid XML
An XML document can be well-formed (follows XML syntax rules) without being valid against a schema. Well-formed means: every opening tag has a closing tag, attribute values are quoted, elements are properly nested, and there is exactly one root element. Valid means the document also conforms to a DTD (Document Type Definition) or XSD (XML Schema Definition) that defines which elements and attributes are allowed. This tool checks well-formedness — full schema validation requires the DTD or XSD.
How to use this tool
- Paste your XML — minified API response, copied config file, or SOAP envelope — into the editor.
- Click Format.
- Review the indented output on the right. If the XML is malformed, the error message identifies the problem.
- Copy the formatted XML back to your project or editor.
XML input
<?xml version="1.0"?><catalog><book id="bk101"><title>XML Developer Guide</title><author>Gambardella, Matthew</author><price>44.95</price><genre>Computer</genre></book><book id="bk102"><title>Midnight Rain</title><author>Ralls, Kim</author><price>5.95</price><genre>Fantasy</genre></book></catalog>
Formatted XML
XML result