In short: what does an XML formatter do?
An XML formatter takes raw, minified or messy XML and re-indents it into a clean, readable structure while validating that it is well-formed. This toolkit also lets you minify XML, explore it as an interactive tree, test XPath expressions, compare two documents, convert XML to JSON, CSV or YAML, and generate code models and an XSD schema — all 100% in your browser, with no data ever uploaded.
Format & validate
Beautify with custom indentation and catch errors with exact line numbers.
Tree explorer
Browse, search and copy the XPath of any element, attribute or value.
XPath tester
Run XPath expressions against your document and see matching nodes live.
Convert anything
XML to JSON, CSV or YAML — and JSON back to XML — in one click.
Schema & models
Generate an XSD plus TypeScript, Python, Go, C#, Java & GraphQL types.
100% private & XXE-safe
Runs in your browser; never resolves external entities or DTDs.
What is XML?
XML (eXtensible Markup Language) is a text-based markup language for storing and transporting structured data. Standardized by the W3C in 1998, it was designed to be both human-readable and machine-readable, and to be completely independent of any platform, language or vendor. Unlike HTML — which has a fixed vocabulary of tags like <p> and <div> — XML lets you invent your own element and attribute names to describe exactly the data you are modeling.
An XML document is built from elements (delimited by start and end tags), attributes (name/value pairs on a start tag), text content, comments, CDATA sections and an optional declaration such as <?xml version="1.0" encoding="UTF-8"?>. Every well-formed document has exactly one root element that contains everything else, forming a strict tree. Because that tree maps naturally onto hierarchical data, XML became the backbone of countless formats and protocols: SOAP web services, RSS and Atom feeds, SVG vector graphics, Office Open XML (DOCX, XLSX), Android layouts, Maven and Spring configuration, sitemaps and much more.
XML formatting — also called beautifying or pretty-printing— is the process of adding consistent indentation and line breaks so the document's hierarchy is visually obvious. Machine- generated XML is frequently emitted as one long line to save bytes, which makes it nearly impossible to read. A formatter parses that XML into a tree and re-serializes it with the indentation you choose, so nested elements line up cleanly and you can scan the structure at a glance.
XML formatting guide: how beautifiers work
Under the hood, an XML beautifier performs a two-step dance: parse, then serialize. First the raw text is fed into an XML parser, which walks the characters and builds an in-memory tree of elements, attributes, text and other nodes — reporting an error the instant the syntax breaks the rules. Once that tree exists, the serializer writes it back out, increasing the indentation level each time it descends into a child element and decreasing it on the way out.
Good pretty-printing is more nuanced than simply adding tabs. A quality formatter keeps a short element with a single text child on one line (<title>Hello</title>) for readability, but expands elements that contain child elements onto separate lines. It preserves CDATA sections and comments verbatim, keeps attribute order stable so diffs stay clean, and collapses the meaningless whitespace between tags while protecting significant whitespace inside text. This tool lets you choose 2 spaces, 4 spaces, tabs or a custom indent width, and because every step runs locally in your browser, your data never leaves your device.
Minification is the inverse operation: the formatter drops the whitespace-only text nodes that exist purely for layout, producing the smallest possible document for transport or storage. The tool reports the original size, the minified size and the exact percentage saved so you can quantify the win.
XML validation explained
XML defines two distinct levels of correctness, and it is important to understand the difference. A document is well-formed when it obeys XML's core syntax rules; it is validwhen, in addition, it conforms to a schema (a DTD or XSD) that defines the allowed structure.
For a document to be well-formed it must satisfy rules such as:
- There is exactly one root element wrapping all other content.
- Every start tag has a matching end tag, or is a self-closing empty element (
<br/>). - Elements are properly nested — they may not overlap.
- All attribute values are wrapped in matching single or double quotes.
- The reserved characters
<and&are escaped in text as<and&. - Element and attribute names are case-sensitive and follow XML naming rules.
This tool's validator checks well-formedness in real time and goes beyond a simple pass/fail:
- Exact line and column — jump straight to the first error instead of scanning hundreds of lines.
- Plain-English explanations — understand why the document is invalid, not just that it is.
- Suggested fixes — get an actionable recommendation for each error.
- Notes — non-fatal observations like a missing declaration or multiple root elements are surfaced too.
For schema-level validation, you can generate a starter XSD from a representative sample and use it as the contract that future documents must satisfy — catching breaking changes long before they reach production.
XML vs JSON: which should you use?
JSON overtook XML as the default format for web APIs, but the two coexist for good reasons. Both represent hierarchical data; they differ in verbosity, capability and ergonomics.
| Aspect | XML | JSON |
|---|---|---|
| Verbosity | Verbose — paired open/close tags | Compact — no closing tags |
| Attributes | First-class attributes on elements | No attributes (keys only) |
| Data types | Everything is text | Native number, boolean, null |
| Comments | Supported | Not supported |
| Namespaces | Built-in (xmlns) | None |
| Schema / validation | XSD, DTD, RELAX NG | JSON Schema |
| Mixed content | Yes (text + elements) | Awkward |
| Best for | Documents, config, SOAP, feeds | Web & mobile APIs, configs |
Choose JSON for lightweight, high-throughput web and mobile APIs where payload size and parsing speed dominate. Choose XML when you need attributes, namespaces, mixed content, comments or rich schema validation — document formats, enterprise messaging, financial standards and configuration files. When you need to move between the two, this tool converts XML to JSON (and back) in a single click.
XML best practices
- Always declare encoding. Start documents with
<?xml version="1.0" encoding="UTF-8"?>so parsers interpret bytes correctly. - Use elements for data, attributes for metadata. Put the core data in child elements and reserve attributes for identifiers, flags and units that describe that data.
- Pick one naming convention and stick to it. Whether camelCase, PascalCase or kebab-case, consistency makes documents predictable and tooling-friendly.
- Escape reserved characters. Replace
<,>and&with entities, or wrap free-form text in a CDATA section. - Keep one root element. A well-formed document has exactly one top-level element; wrap collections in a container.
- Define a schema for contracts. Use an XSD to document and enforce the structure other systems depend on, and validate incoming documents against it.
- Use namespaces to avoid collisions. When mixing vocabularies, qualify elements with a namespace prefix so names never clash.
- Minify in production, beautify in development. Ship the smallest payload to consumers, but keep a formatted copy for debugging.
Common XML errors (and how to fix them)
The overwhelming majority of "not well-formed" problems fall into a handful of recurring categories:
| Error | Cause | How to Fix |
|---|---|---|
| Mismatched tag | </price> closing a <cost> element | Make every end tag match its start tag |
| Unclosed tag | A <book> with no </book> | Close every element you open |
| Improper nesting | <a><b></a></b> | Close inner elements before outer ones |
| Unescaped & | AT&T written literally | Use &amp; (or a CDATA section) |
| Unescaped < | 5 < 10 in text content | Use &lt; for a literal less-than |
| Unquoted attribute | id=bk101 with no quotes | Wrap values: id="bk101" |
| Multiple roots | Two top-level elements | Wrap everything in one root element |
| Missing declaration | No <?xml …?> prolog | Add the declaration (recommended) |
Our validator detects each of these and reports the exact location, while the Auto-fix button repairs the most common ones — escaping bare ampersands and normalizing smart quotes — in a single click.
XML namespaces explained
As documents combine vocabularies from different sources, two elements can easily end up with the same name but different meanings — a <table> of furniture versus an HTML <table>. XML namespaces solve this by qualifying names with a unique URI, so the parser can tell them apart.
A namespace is declared with an xmlns attribute, usually bound to a short prefix: xmlns:h="http://www.w3.org/TR/html4/". An element written as <h:table>then belongs to that namespace. A default namespace (xmlns="…" with no prefix) applies to an element and its unprefixed descendants. The URI is an identifier, not a location — the parser never fetches it. Our analyzer counts and lists every namespace your document declares so you can audit them at a glance.
XML schemas explained: DTD, XSD and validation
A schema is a formal description of what a class of XML documents is allowed to contain. It turns an informal agreement ("every order has a customer and one or more line items") into a machine-checkable contract. There are several schema languages:
- DTD (Document Type Definition) — the original, compact schema language. It defines elements, attributes and entities but has no data-type system and isn't itself written in XML.
- XSD (XML Schema Definition) — the W3C standard and the most widely used today. It is written in XML, supports rich data types (integer, date, decimal, custom restrictions), and expresses cardinality with
minOccursandmaxOccurs. - RELAX NG — a simpler, expressive alternative popular in document publishing.
Schema validation checks that a well-formed document also matches its schema: the right elements appear in the right order, attributes have valid types, and required fields are present. This tool can generate a starter XSD directly from a sample document — inferring element occurrence and simple types — giving you a contract you can refine and reuse to validate future data.
XPath guide: querying XML
XPath (XML Path Language) is a query language for selecting nodes in an XML document, much like a file-system path selects files. It is the foundation of XSLT transformations, XQuery and many libraries that extract data from XML.
A few of the most common patterns:
/catalog/book— everybookthat is a direct child of the rootcatalog.//title— everytitleelement anywhere in the document./catalog/book[2]— the secondbook(XPath indexes are 1-based).//book/@id— theidattribute of everybook.//book/title/text()— the text content of each book title.
Our XPath explorer evaluates expressions against your document in real time and lists the matching nodes, and the tree viewer generates the absolute XPath of any node you select so you can copy it straight into your XSLT, code or test assertions.
XML for API development & data integration
XML remains central to enterprise integration — SOAP services, financial messaging (ISO 20022, FIXML), healthcare (HL7), publishing and government data all rely on it. Good tooling pays for itself many times over. Here is a practical workflow this toolkit supports end to end:
- Inspect the payload. Paste a response or fetch it from a URL or feed, then format it to understand the shape of the data.
- Validate well-formedness. Confirm the document parses cleanly before you build against it.
- Explore and query. Use the tree viewer and XPath explorer to locate the exact nodes you need.
- Generate models. Produce TypeScript, Python, Go, C#, Java or GraphQL types so your client code is type-safe from day one.
- Lock in a schema. Generate an XSD to document the contract and validate future payloads against it.
- Convert when needed. Transform XML to JSON, CSV or YAML to feed downstream systems, or convert JSON back into XML.
- Diff for breaking changes. Compare old and new payloads to spot added, removed or changed nodes instantly.
Because everything runs client-side — and the parser never resolves external entities or fetches DTDs — you can safely paste internal endpoints, tokens and sensitive payloads. Nothing is transmitted to a server, which also structurally protects you against XXE attacks.
Frequently asked questions
XML (eXtensible Markup Language) is a text-based markup language for storing and transporting structured data. Unlike HTML, XML has no predefined tags — you define your own elements and attributes to describe the data. It is self-descriptive, platform-independent and human-readable, which is why it powers configuration files, document formats (DOCX, SVG, RSS), SOAP web services and countless enterprise systems.
Paste, upload or fetch your XML into the editor and click Format (or press Ctrl/Cmd + Shift + F). The tool parses your document and re-indents it with the indentation you choose — 2 spaces, 4 spaces, tabs or a custom width — so the element hierarchy lines up cleanly. Everything runs locally in your browser, so your data is never uploaded.
Validation runs automatically as you type. The tool checks that your document is well-formed: every start tag has a matching end tag, tags are correctly nested, attributes are quoted, and there is a single root element. If something is wrong, you get the exact line and column, a plain-English explanation and a suggested fix.
Well-formed XML follows the basic syntax rules of XML — proper nesting, matched tags, quoted attributes and one root element. Valid XML is well-formed AND conforms to a schema (DTD or XSD) that defines which elements, attributes and structures are allowed. This tool checks well-formedness in real time and can also check documents against an XSD schema you provide.
The most common causes are: a missing or mismatched closing tag, improperly nested elements, unquoted attribute values, more than one root element, an unescaped ampersand or angle bracket in text, or an unterminated comment or CDATA section. The validator pinpoints the first error’s line and column and explains the likely cause.
Beautifying (pretty-printing) adds consistent indentation and line breaks to XML so its nested structure becomes visually obvious. API responses and machine-generated XML are often minified onto a single line; the beautifier parses the document and re-serializes it with clean indentation so you can read and debug it at a glance.
Minification removes the whitespace-only text nodes between elements (indentation and line breaks) that exist purely for readability. Because this formatting can account for a large share of a pretty-printed file, removing it meaningfully shrinks payloads for transport and storage. The tool reports the original size, the minified size and the exact percentage saved.
A tree viewer renders XML as a collapsible hierarchy of elements instead of raw text. You can expand and collapse nodes, inspect attributes, see how many children each element has, search tags, attributes and values, and copy the absolute XPath of any node — making large or deeply nested documents far easier to explore.
XPath (XML Path Language) is a query syntax for navigating XML, similar to a file-system path. An expression like /catalog/book[2]/title selects the title of the second book element. This tool generates the XPath for any node you select and includes an XPath tester so you can run expressions against your document and see the matching nodes.
Open the Convert tab and choose JSON. The tool maps elements to object keys, attributes to "@"-prefixed keys and text content to a "#text" field, turning repeated elements into arrays automatically. You can also convert XML to CSV or YAML, and convert JSON back into XML — all in your browser.
XSD (XML Schema Definition) is a language for describing the structure of an XML document: which elements and attributes are allowed, their data types, and how often they can appear. Validating an XML file against its XSD confirms the document not only is well-formed but also matches the agreed contract. This tool can generate a starter XSD from a sample document and check basic conformance.
Yes. The Generate tab infers strongly-typed models from your XML structure in TypeScript, Python, Go, C#, Java, JavaScript (JSDoc) and GraphQL. It merges element shapes, detects optional fields and maps attributes and text content, giving you type-safe models to drop straight into your codebase.
Open the Compare tab, paste your original XML on the left and the modified XML on the right. The tool performs a structural comparison and highlights every added, removed and changed element, attribute and value, with a summary count of each — ideal for reviewing configuration changes or API version diffs.
Namespaces let you combine elements from different vocabularies in one document without name collisions. They are declared with an xmlns attribute and usually bound to a prefix, e.g. xmlns:h="http://www.w3.org/TR/html4/". An element written as <h:table> then belongs to that namespace. The analyzer counts and lists the namespaces used in your document.
A CDATA section (<![CDATA[ ... ]]>) tells the parser to treat its contents as raw character data rather than markup. It is used to embed text that contains characters like < and & without escaping them — for example, snippets of code or HTML inside an XML document. The tool preserves CDATA sections when formatting.
Five characters have special meaning in XML and must be escaped in text and attribute values: < becomes <, > becomes >, & becomes &, the double quote becomes " and the apostrophe becomes '. An unescaped & or < is the single most common cause of "not well-formed" errors. The Auto-fix action escapes bare ampersands for you.
Yes. The tool is 100% free with no sign-up, no usage limits and no watermarks. Format, validate, minify, convert, compare and generate as much XML as you like, as often as you like.
Completely. All parsing and processing happen locally in your browser using JavaScript. Your XML is never uploaded to a server, never logged and never stored remotely. The parser is also hand-written and never resolves external entities or DTDs, which structurally protects against XXE (XML External Entity) attacks.
An XXE (XML External Entity) attack abuses XML parsers that resolve external entity references to read local files or make network requests. This tool uses a custom parser that decodes only the five predefined entities and numeric character references — it never fetches DTDs or resolves external entities — so malicious XXE payloads cannot reach the file system or network.
Yes. Parsing is iterative to stay safe on deeply nested documents, the tree view renders lazily, and live features throttle automatically for very large inputs so the interface stays responsive even with multi-megabyte files. You can also upload files up to 50 MB.
Use the Clean action to remove comments, strip empty elements and collapse redundant whitespace in a single pass. Combined with Format, it turns noisy machine-generated or copy-pasted XML into a tidy, readable document.
Common actions are bound: Ctrl/Cmd + Shift + F to format, Ctrl/Cmd + Shift + M to minify, Ctrl/Cmd + K to clear, Ctrl/Cmd + S to download and Ctrl/Cmd + / to open the shortcuts panel. Native undo/redo (Ctrl/Cmd + Z / Y) works in the editor.
JSON is more compact, maps directly onto native data structures and is faster to parse, which makes it the default for modern web and mobile APIs. XML is more verbose but supports attributes, namespaces, mixed content, comments and rich schema validation (XSD), so it remains the better fit for documents, configuration formats and many enterprise and legacy systems.
Yes. Because everything runs client-side, formatting, validation and conversion keep working without a connection once the page has loaded. The interface is fully responsive and optimized for phones, tablets and desktops.
Related Tools
Explore More Tools
Go ad-free & unlock power features
- Zero ads, faster focused workflow
- Upload 50MB+ files & batch process
- Priority AI type & schema generation