XML Formatter & Beautifier
Format, beautify, minify, validate, and convert XML documents instantly. Features syntax highlighting, tree view, XPath testing, XML-to-JSON conversion, and format presets — all client-side.
<?xml version="1.0"?><catalog><book id="bk101"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><price>44.95</price></book></catalog>Ready locally via WebAssembly & JavaScript
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<price>44.95</price>
</book>
</catalog>100% Client-Side • Zero Server UploadUnlike forgiving HTML parsers that quietly guess where a missing closing tag belongs, W3C XML 1.0 follows draconian error handling: a single unescaped &, mismatched tag capitalization, or stray character before the <?xml?> prolog invalidates the entire payload. XML Formatter & Beautifier combines a dual-pane Monaco Editor with the browser's native DOMParser, giving you instant well-formedness validation, configurable pretty-printing, minification, collapsible DOM tree inspection, XPath 1.0 querying, and XML-to-JSON conversion—all executed privately on your local machine.
Enforcing W3C XML 1.0 Well-Formedness in the Browser
Half a second after you stop typing or pasting, the editor runs new DOMParser().parseFromString(xml, "application/xml"). Because this uses the browser engine's full standards-compliant XML parser rather than a loose regex check, it enforces every core XML 1.0 (Fifth Edition) grammatical constraint:
- Single root element: Exactly one top-level document element must wrap all sibling nodes.
- Strict case sensitivity:
<OrderItem>and</orderItem>are distinct names and immediately fail pairing validation. - Quoted attribute values: Every attribute must be enclosed in matching single (
'...') or double ("...") quotes, and duplicate attribute names on the same element are illegal. - Predefined character entities: Raw
<and&characters inside text nodes or attribute values must be escaped as<and&(alongside>,", and'where contextually required)—unless wrapped inside an explicit<![CDATA[ ... ]]>section.
Diagnosing Common Parser Errors by Line and Column
When the parser encounters malformed markup, it injects a <parsererror> node containing the engine's exact failure message. The validation banner extracts both the line and column coordinates automatically. Three culprits account for the vast majority of production XML failures:
- Unescaped query-string ampersands: URLs like
<link>https://api.example.com?a=1&b=2</link>break parsing because&bis read as an unterminated entity reference. Fix it by writing&b=2. - Double hyphens inside comments: Per the XML 1.0 spec,
--is forbidden anywhere inside<!-- ... -->comments (even inside commented-out CLI flags like<!-- --verbose -->). - Leading whitespace or BOM before the XML declaration:
<?xml version="1.0" encoding="UTF-8"?>must start at byte 0, line 1, column 1; even a single leading space triggers a processing-instruction syntax error.
If you are authoring web markup that allows void tags (<img>, <br>) and relaxed attribute quoting, use our dedicated HTML Formatter instead of strict XML mode.
Pretty-Printing, Mixed-Content Whitespace, and Minification
Formatting splits adjacent tag boundaries (><) onto clean lines, tracks element nesting depth across opening, self-closing (<tag />), and closing tags, and applies your chosen 2 Spaces, 4 Spaces, or Tab indentation. Conversely, Minify removes redundant inter-tag indentation (/>\s+</g → ><), shrinking verbose SOAP envelopes, API fixtures, and sitemap feeds—for example, files generated by the Sitemap XML Generator—into compact single-line strings.
Keep one XML specification subtlety in mind: XML distinguishes data-oriented documents (config files, RPC payloads, catalogs) from mixed-content documents (XHTML, DocBook, TEI). In mixed content like <p>Click <b>Save</b> <i>now</i>.</p>, the single space between </b> and <i> is semantically significant; minifying between adjacent inline tags collapses Save now into Savenow. Always keep pretty-printing or preserve xml:space="preserve" sections intact when editing prose-oriented XML.
Navigating Deep Schemas with Tree View and XPath 1.0
When inspecting a 4,000-line Maven pom.xml, SAML 2.0 assertion, or financial ISO 20022 message, linear scrolling hides parent-child hierarchy. Switching to the Tree Viewer renders the parsed DOM interactively with the first two levels expanded, color-coding element tags, attribute key-value pairs, CDATA/text payloads, and <!-- comments --> so you can fold unrelated branches cleanly.
For surgical extraction, open the XPath Tester tab. Queries run directly against the live XML document via doc.evaluate(xpathQuery, doc, resolver, XPathResult.ANY_TYPE, null) and serialize up to 500 matching nodes with XMLSerializer:
//book[@category='programming' and price < 45]/title
//item[contains(@sku, 'US-')]/stock/text()
//*[local-name()='loc']
Handling Default and Prefixed Namespaces in XPath
The built-in doc.createNSResolver(doc.documentElement) automatically resolves declared namespace prefixes (such as soap:Envelope or atom:entry) declared on the root element. However, XPath 1.0 specifies that unprefixed node tests never match a default namespace (xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"). Whenever a sitemap or Office Open XML document declares an unprefixed xmlns, match elements cleanly with local-name()—for example, //*[local-name()='url']/*[local-name()='loc']—to bypass default-namespace binding quirks.
Deterministic XML-to-JSON Translation Rules
Because XML supports attributes, ordered sibling tags, comments, and mixed text that have no single native JSON equivalent, predictable conventions matter when bridging legacy XML systems with REST APIs. The XML to JSON tab applies deterministic DOM-to-object rules that you can further inspect or validate in our JSON Formatter:
| XML Construct | Example XML Snippet | Formatter & Tree View Behavior | Resulting JSON Representation |
|---|---|---|---|
| Simple Element | <status>OK</status> | Indented leaf node with text child | "status": "OK" |
| Element with Attributes | <price cur="USD">29.99</price> | Attributes highlighted inline on open tag | "price": { "@attributes": { "cur": "USD" }, "#text": "29.99" } |
| Empty Self-Closing Tag | <flag enabled="true" /> | Rendered as single self-closing node | "flag": { "@attributes": { "enabled": "true" } } |
| Repeated Sibling Tags | <tag>xml</tag><tag>api</tag> | Stacked sibling branches under parent | "tag": ["xml", "api"] (auto-promoted array) |
| CDATA Section | <raw><![CDATA[a < b & c]]></raw> | Displayed verbatim without entity escaping | "raw": "a < b & c" |
| XML Comments | <!-- Build 42 --> | Italicized muted node in Tree Viewer | Stripped during JSON object serialization |
| Namespaces | <ns:id xmlns:ns="urn:x">7</ns:id> | Preserved verbatim; queryable via resolver | "ns:id": { "@attributes": { "xmlns:ns": "urn:x" }, "#text": "7" } |
Between live Monaco syntax highlighting, debounced DOMParser validation, interactive DOM folding, XPath 1.0 testing, and deterministic JSON output, every inspection step completes locally inside a single browser tab.
How to Use XML Formatter & Beautifier
Paste raw XML into the Monaco input editor, upload a local .xml file, or click Import URL to fetch a CORS-enabled feed.
Check the live validation banner above the editor; if any tag or entity breaks XML 1.0 rules, jump directly to the reported line and column.
Choose 2 Spaces, 4 Spaces, or Tabs beside the Format button and click Format—or click Minify to strip inter-tag whitespace.
Switch to the Tree Viewer tab to expand or collapse nested elements, inspect attribute values, and verify comment or CDATA placement.
Open the XPath Tester tab, type an expression such as //item[@active='true']/title, and run it to inspect serialized node matches.
Visit the XML to JSON tab to copy or export the equivalent JSON representation, or download your cleaned XML output.
Real Examples
Beautify Minified XML
Convert a single-line XML payload into a readable hierarchy.
<?xml version="1.0"?><catalog><book id="bk101"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><price>44.95</price></book></catalog><?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<price>44.95</price>
</book>
</catalog>Detecting XML Errors
Identifying an unclosed tag in an XML document.
<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</note>Error: Malformed XML. Opening and ending tag mismatch: body line 1 and note.Frequently Asked Questions
How does the validator catch XML syntax errors and pinpoint their exact location?
How are XML attributes and repeated sibling elements represented when converting XML to JSON?
Why does my XPath query return zero matches on an XML document with a default xmlns namespace?
When should I avoid minifying XML payloads?
Can I fetch an XML feed from a URL, and are my local XML files kept private?
Key Features
- Real-time W3C XML 1.0 well-formedness validation via native DOMParser with exact line and column diagnostics
- Dual-pane Monaco Editor workspace with XML syntax highlighting, light/dark theme sync, and Word Wrap toggle
- Configurable pretty-printing (2 spaces, 4 spaces, or Tabs) plus one-click inter-tag XML minification
- Interactive collapsible DOM Tree Viewer displaying elements, attributes, text nodes, CDATA blocks, and comments
- Live XPath 1.0 query tester powered by document.evaluate() with namespace resolution and 500-node match capping
- Instant XML-to-JSON converter (@attributes / #text mapping), URL import, .xml upload, and 10-slot local history
Common Use Cases
- Debugging minified SOAP API responses, SAML assertions, and enterprise EDI payloads with exact syntax-error locations
- Auditing XML sitemaps, RSS/Atom syndication feeds, and Maven pom.xml or AndroidManifest.xml configuration files
- Testing XPath 1.0 expressions against nested product catalogs before embedding queries into scrapers or XSLT pipelines
- Converting legacy XML webhook responses into structured JSON objects for modern REST microservices and frontend apps
- Exploring deeply nested 1,000-line configuration hierarchies interactively using the collapsible DOM Tree Viewer
- Compacting verbose XML request templates into single-line payloads for curl scripts, Postman collections, or message queues
Related Tools
Explore More Tools in This Category
View All Developer & Utility ToolsMarkdown Previewer & Editor
Write and preview GitHub Flavored Markdown in real time inside a split-screen Monaco editor. Supports syntax highlighting, interactive table of contents, live statistics, and HTML, PDF, or .md export locally in your browser.
SQL Formatter & Beautifier
Format, beautify, minify, and validate SQL queries across nine relational and cloud warehouse dialects with Monaco syntax highlighting, query complexity scoring, and line-level diff checks — 100% client-side.
YAML Formatter & Beautifier
Format, beautify, minify, validate, and convert YAML documents instantly. Supports Kubernetes YAML, Docker Compose, GitHub Actions, YAML-to-JSON conversion, diff comparison, and linting — all client-side.
Word Counter & Character Counter
Analyze your writing in real time. Count words, characters, sentences, paragraphs, and spaces. Calculate keyword density, estimated reading time, readability scores, and platform limits.
Case Converter
Transform text casing instantly. Convert between UPPERCASE, lowercase, Title Case, Sentence case, AP/Chicago styles, camelCase, snake_case, and kebab-case. Clean whitespace and audit SEO title lengths.
Regex Tester & Live Debugger
Validate ECMAScript regular expressions in real time with match highlighting, named capture group inspection, flag toggles, and catastrophic backtracking diagnostics.
JSON to CSV Converter
Flatten nested JSON objects and arrays into RFC-4180 compliant CSV spreadsheets with configurable delimiters and UTF-8 BOM encoding directly in your browser.
CSV to JSON Converter
Transform RFC-4180 CSV datasets into clean, strongly typed JSON arrays with automatic delimiter detection and number/boolean coercion right in your browser.