What this XML formatter checks
The browser parses the input as an XML document. A successful parse confirms basic well-formedness, including matching tags and a single document element. The workbench then serializes the DOM with consistent indentation and reports the root element, namespace, element count and attribute count.
All of this happens inside the open tab. The script on the page makes no request to a server, so pasted text stays on the device. The page also asks for no external entity, DTD or schema to be loaded. The XML Recommendation lets a processor that does not validate check only the document entity, so external declarations stay outside the check. Namespaced documents work, and the report names the namespace URI of the root element when there is one.
Error wording and the reported position come from the browser engine. The HTML Standard leaves the content of the error node open, so Chromium, Firefox and Safari can describe the same mistake differently. The size of the input is limited by browser memory and document complexity, and no maximum has been measured.
What an XML formatter does
A formatter reads a document, confirms that it parses and writes it out again with line breaks and indentation. Beautifier is another name for the same job: the content stays, the layout becomes readable. A minifier works in the other direction and strips the layout that a person added, which is useful for compact transport. The Minify button on this page does that.
A validator is a different tool. It compares a document with a schema and reports rule violations, which needs a grammar the formatter does not have. A formatter answers only the first question, whether the text is XML at all.
How to format an XML document online
- Paste the document into the input field, or start from the sample that is already loaded.
- Choose Format XML. The status line changes to a syntax result and the indented text appears in the output field.
- If the status reports a parse error, read the message and fix the earliest problem in the input. Later messages are often consequences of the first one. Run the formatter again.
- Choose Copy to take the formatted text, or Minify for the compact form. Reset sample restores the example.
Replace the original file only after a comparison. The formatted text works best as a reading copy. When JSON is the goal rather than readable XML, the XML to JSON converter applies fixed rules to the same parsed document.
What makes XML well-formed?
The XML 1.0 Recommendation of the W3C calls a text object well-formed when it matches the document production and satisfies every well-formedness constraint. In practice that comes down to a few visible rules.
- Exactly one root element contains everything else.
- Every start tag has a matching end tag, and elements nest without overlapping. Tag names are case-sensitive.
- Attribute values are quoted.
- The characters that start markup, such as
<and&, are written as references inside text.
Parsers name these failures in their own words. The command-line parser xmllint, built on libxml2, reports Opening and ending tag mismatch for <a><b></a></b>, Extra content at the end of the document for <a/><b/> and AttValue: " or ' expected for an unquoted attribute value.
Well-formed is a statement about syntax. Validity, meaning agreement with a schema, is a separate property.
What it deliberately does not claim
Well-formedness is not schema validity. An XML document may parse correctly and still violate an XSD, DTD, RELAX NG grammar or Schematron rule set. Use the output as a syntax checkpoint before standards validation.
Formatting changes text, not the governing data model
The formatter reparses and serializes the document, so indentation between elements can change and insignificant whitespace may be normalized. The XML Recommendation requires a processor to pass all characters that are not markup on to the application, and it offers xml:space with the values default and preserve for documents that care. Attribute order is not an XML semantic guarantee, since the specification says the order of attribute specifications is not significant. Namespace prefixes are aliases for namespace URIs, and a visually tidy result does not prove that downstream canonicalization or digital-signature requirements are preserved.
Canonical XML 1.1 is the relevant yardstick there. It treats two documents with the same canonical form as logically equivalent in the application context, signatures are computed over that form, and it sorts attributes. A formatter does not produce it. Treat the formatted text as a review copy unless a byte-for-byte or canonical XML workflow has explicitly approved the transformation.
Mixed content needs particular care because whitespace between words and child elements can carry meaning. The formatter sets its own line breaks and indentation, so whitespace in and between elements can change. A human reviewer should compare representative rendered or processed output before replacing an authoritative mixed-content document. The page itself fetches no external entities, DTD subsets, schema imports or stylesheets.
How XML works in brief
An XML document is a tree. Elements form the branches, attributes attach small facts to an element, and text sits inside. In the sample above, catalog is the root, item carries the attribute id, and price carries currency next to its text. Namespaces give names a home: the default namespace on catalog declares which vocabulary the elements belong to.
A parser turns the characters into that tree, and programs read the tree rather than the text. This is also why the layout of tags is mostly free. For how XML compares with JSON as a data format, see XML vs JSON.
A practical XML debugging sequence
First reduce the failing message while preserving its declaration, namespace bindings and problematic node. Fix the earliest parser error because later diagnostics may be consequences of the first malformed token. Then run the clean document through the exact XSD, DTD, RELAX NG or Schematron processors used by the receiver. Retain the reduced invalid fixture and its expected error category in source control so the same syntax regression cannot return unnoticed.
For schema design questions, continue with the XSD Pattern Analyzer or read the XML Schema tutorial.
What to inspect after the document parses
Check the XML declaration against the bytes used to store or transmit the document. A declaration naming UTF-8 does not repair content that was decoded with another character set, and a JavaScript string no longer exposes the original byte-order mark. If the failure involves corrupted characters, reproduce it from the original bytes in the receiving parser rather than relying on pasted text alone.
Review expanded names, not only visible prefixes. Two elements with different prefixes can have the same namespace name, while matching prefixes can denote different URIs in different scopes. Confirm the reported root namespace against the vocabulary contract and inspect unprefixed attributes separately because the default namespace does not apply to them.
Next distinguish syntax cleanup from application change. Reformat a disposable copy, compare parsed structures, and keep the original when signatures, canonicalization, mixed content or whitespace-sensitive applications are involved. For messages entering a pipeline, validate size limits and disable unneeded external resolution in the authoritative parser. A formatter is useful at the first debugging boundary, but secure parsing policy belongs to the consuming system.
Evidence worth retaining
A strong issue report includes the minimized original, the earliest parser diagnostic, the corrected document and the exact production parser or validator version. Note whether the text came from a file, HTTP message, database or already-decoded application string. These details separate an XML grammar problem from a transport encoding, truncation or content-type problem.
Frequently asked questions
01What is an XML formatter?
It is a tool that reads an XML document, checks that the syntax holds together and writes the same content back with line breaks and indentation. The result is easier for a person to read, while the data stays the same. Some formatters also report the root element or count elements.
02How can I format an XML document?
Paste the document into the input field and run the formatter. If the syntax is broken, the tool names the first problem instead of producing output, and the document needs that fix before it can be indented. Keep the original file and use the formatted text as a copy.
03How can I beautify my XML code?
Beautifying means the same thing as formatting: consistent indentation and one tag per line. A one-line export or a file with irregular spacing becomes a readable tree after a single pass. The reverse step, which removes the added whitespace again, is called minifying.
04How do I convert XML to readable format?
Run the text through a formatter and read the indented tree from the outside in: root element first, then its children. A parse error means the text is not valid XML yet, which is often a truncated file or an unescaped ampersand. If the goal is a different notation instead, the XML to JSON converter changes the structure rather than the layout.
05How does XML work?
XML marks up data with nested elements, optional attributes and text. A parser reads the characters and builds a tree, and applications then work on that tree instead of the raw text. Namespaces keep names from different vocabularies apart.