XML tools
XML Formatter, Validator & Minifier
Format XML online: paste, type or open an .xml file, then beautify, validate
or minify it in the same editor. Invalid documents are left untouched while the error is
reported by line and column. Nothing is uploaded — everything happens in your browser.
Paths start at the root element: [0] picks one repeated sibling, [*] matches all of them, .@id reads an attribute, .#text reads an element’s text.
Loading the editor…
How to format XML online, validate it or minify it
- Add your XML. Paste it into the editor, type it, choose
Open file, or drop a
.xmlfile onto the editor. - Choose an indentation. Pick the code indentation you want — 1, 2, 4 or 8 spaces, or tabs. The preference is remembered and the document is reformatted immediately when you change it.
- Run an action. Format indents every level, Minify removes the whitespace between elements, and Validate reports whether the document is well-formed without altering it.
- Find an element by path. Type an element path such as
company.employee[0].nameinto the Path finder above the editor and press Find. It highlights that exact element, or explains why the path does not exist. - Fold what you do not need. Chevrons in the gutter fold a single element; Collapse All folds the entire tree.
- Copy or download. Take the result as clipboard text or as a
.xmlfile.
XML beautifier before and after
This compact document has no indentation, so its structure is hard to read. Formatting adds one level of indentation per nesting level using the indentation you selected.
Compact input
<note><to>Ada</to><from>Grace</from><body priority="high">Ship it & celebrate</body></note> After Format with 2-space indentation
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Ada</to>
<from>Grace</from>
<body priority="high">Ship it & celebrate</body>
</note> Minifying the formatted result produces the compact input again, character for character. That round trip is a quick way to confirm nothing was rewritten.
The whitespace rules, stated precisely
XML whitespace is sometimes data, so a formatter that silently rewrites it is dangerous. This tool applies exactly three rules, and nothing else changes:
- Whitespace between elements is regenerated. The blank space used to pretty-print a document is replaced using your indentation setting.
- A lone text child is trimmed. When an element contains nothing but
text —
<title>Draft</title>— that text has its surrounding whitespace removed, which is what lets already-formatted documents reflow. There is no neighbouring markup whose spacing could be affected. - CDATA is never touched. Its content is literal by definition.
Anything else — including mixed content, where text and elements sit side by side — is reproduced exactly:
Mixed content keeps its spacing through format and minify
<p>Read the <strong>docs</strong> first.</p> Common XML syntax errors and how to fix them
Mismatched or unclosed elements
Every start tag needs a matching end tag in the right place. The validator names the tag it expected and where the mismatch occurs:
Invalid — the second {book} is closed with {/catalog}
<catalog>
<book>
<title>Draft</title>
</book>
<!-- the next line closes the wrong element -->
<book>
<title>Final</title>
</catalog>
Element names are case-sensitive, so <Item> is not closed by
</item>.
More than one root element
An XML document must have exactly one top-level element. Sibling roots such as
<a/><b/> are invalid — wrap them in a single container element.
Unquoted attribute values
<book id=bk101> is invalid; attribute values must be quoted, as in
<book id="bk101">.
Unescaped markup characters
Inside text, write & for an ampersand and < for
a less-than sign, or wrap the content in a CDATA section. A bare
& is reported as an error.
Unterminated comment or CDATA section
Comments must end with --> and CDATA sections with ]]>.
If either is left open, the validator says so and points at the opening construct.
XML formatter features
- One editor, in place. Format, validate and minify operate on the content you can see and replace it there — no separate output pane to keep in sync.
- Element-level folding. Real CodeMirror 6 folding from the start tag to the matching end tag, at any nesting depth.
- Attributes kept as written. Quote style, attribute order and spacing are preserved because tags are never re-serialised.
- Clear diagnostics. Line and column positions plus a highlight on the offending line.
- Large documents. The tokenizer is iterative, so deeply nested trees do not overflow the stack.
- XML path finder. Resolve an element path such as
company.employee[0].name, read an attribute with.@idor an element's text with.#text, with autocomplete from the document and a match count for repeated elements. - Accessible themes. Light and dark syntax colours both meet WCAG AA contrast, and the editor can be left with Escape then Tab.
Find an XML element by path with the XML path finder
The path finder resolves an element path against the document that is really in the editor and jumps to the element it names, which is quicker than scrolling through a feed, an SVG or a configuration export to find one tag. It walks the actual element tree rather than the text, so finding an XML element by its path works even when the same tag name occurs dozens of times.
Paths are absolute from the document's single root element — the first segment is the root's own name — and the rest is:
- Element names.
company.employee.namereads child elements, to any depth, by name. - Indexes among matching siblings.
company.employee[0]is the firstemployee; indexes are zero-based and counted only among the elements with that name. Leaving the index out matches every one of them. - Attributes with
.@—company.employee.@idreads that attribute on each matching element. - Text with
.#text—company.employee[0].name.#textreads the content of an element, including the literal content of a CDATA section.
Examples for the document in the editor, derived from its own structure and refreshed whenever the content changes:
XML element path examples
company.employee[0].name → <name>Ada Lovelace</name>
company.employee[*].name → <name>Ada Lovelace</name>, <name>Grace Hopper</name>
company.employee.@id → "e-001", "e-002"
company.employee[0].name.#text → "Ada Lovelace"
company.employee.notes.#text → "Prefers <markup> in tickets." The field suggests element names, attributes and text accessors read from the real document as you type. A malformed path, an element or attribute that does not exist, an index past the end of a repeated element and a missing CDATA or text node each produce their own message, and when several elements match one path the match counter steps through them with every hit highlighted in the editor.
XML formatter frequently asked questions
What is an XML formatter?
An XML formatter (also called an XML beautifier or XML pretty printer) re-indents a compact XML document so its nesting is readable: one level of indentation per element depth, newlines between tags, and consistent alignment. A safe formatter only rewrites the whitespace between elements — attributes, comments, CDATA and text content stay exactly as written.
How do I format XML online?
Paste, type or open an .xml file in the editor above, choose an indentation (1, 2, 4 or 8 spaces, or tabs), and press Format. The document is rewritten in place, and the indentation choice is remembered for next time. Nothing is installed and nothing is uploaded, so it works the same on a shared machine.
How do I validate XML?
Press Validate. The XML validator checks well-formedness without changing the document: every element closed, start and end tags matching and correctly nested, attribute values quoted, exactly one root element, and comments, CDATA sections, processing instructions and DOCTYPE declarations properly terminated. Errors are reported with an exact line and column and highlighted in the editor.
How do I fix XML syntax errors?
Work from the reported line and column. The most common problems are a mismatched or unclosed tag (every start tag needs its matching end tag, and element names are case-sensitive), more than one root element (wrap them in a single container), an unquoted attribute value, an unescaped & or < in text (write & and <, or use a CDATA section), and an unterminated comment or CDATA section. The editor leaves your document untouched and highlights the offending line so you can fix it in place.
What is XML minification?
XML minification removes the whitespace between elements so the file is as small as possible for transport — the opposite of formatting. In this tool it follows the same three whitespace rules as formatting: only the blank space between elements is dropped, a lone text child is trimmed, and CDATA content is never touched, so mixed content keeps its spacing.
Is online XML formatting safe?
Yes, with this tool: the formatter runs entirely in your browser with JavaScript, so your document is never transmitted. That makes it suitable for internal configuration files, export payloads and data covered by a confidentiality agreement. You can verify it yourself in your browser’s network panel — no request carries your document.
How do I change indentation?
Pick 1, 2, 4 or 8 spaces or tabs in the Indentation dropdown and the whole document reformats immediately; the preference is saved between visits. To hide detail, click the chevron beside any element to fold it, or use Collapse All to fold the entire tree (Ctrl-Alt-[ and Ctrl-Alt-] work from the keyboard). Folding only changes the display, never the file.
Does it validate against a DTD, XSD or Relax NG schema?
No. This is a well-formedness checker, not a schema validator. It tells you whether a document is syntactically valid XML, not whether its elements and attributes match a particular schema or namespace design.
Does formatting change my XML?
The structure, elements, attributes, comments, CDATA sections and text are preserved. Three whitespace rules apply, and only these: whitespace between elements is regenerated from your indentation setting, the text of an element that contains nothing but text has its surrounding whitespace trimmed, and CDATA content is never touched. Mixed content such as <p>a <strong>b</strong> c</p> keeps its spacing exactly.
Are attributes, comments and CDATA preserved exactly?
Yes. Every tag is kept as the original text, so attribute order, single or double quotes, and internal spacing all survive formatting and minifying byte for byte. Comments, processing instructions and DOCTYPE declarations are kept verbatim too, and CDATA sections are treated as literal content that is never trimmed, split or re-escaped.
Can I open an .xml file and save the result?
Yes. Use Open file or drag a .xml document onto the editor, and use Download to save the current editor contents as formatted.xml. Minify first if you want the downloaded file to be as small as possible.
How do I find an XML element by its path?
Type the element path into the path finder above the editor and press Find. Paths are absolute from the document’s root element, so company.employee[0].name reads the name of the first employee. The tool highlights that exact element, expanding any folded ancestor on the way, and reports the line and column. Because it walks the real element tree, it finds the element even when the same tag name appears many times in the document.
How do I address an XML attribute or an element’s text in a path?
Append .@name for an attribute and .#text for content: company.employee.@id reads the id attribute of every employee, and company.employee[0].name.#text reads the text inside the first name element. CDATA sections count as text, so .#text returns their literal content. An attribute or text segment is always the last part of a path, and a missing attribute reports the attributes that element does have.
What happens with repeated or missing XML elements?
Repeated siblings are addressed with a zero-based index counted among the elements that match that name, so company.employee[0] is the first employee and company.employee[1] the second, and the wildcard company.employee[*].name matches every employee’s name at once — the fastest way to find an XML element when you do not care which occurrence it is. Leaving the index out matches all of them too, which is how one path can report several elements and step through them. A name that does not exist, an index past the end and a missing root element name each get their own message; if the root name is left out, the tool names the root and offers the corrected path.
Related tool: the JSON formatter
Working with data rather than markup? The JSON formatter, validator and minifier offers the same single-editor workflow, folding and validation for JSON documents — and there is a JSON formatter FAQ for the common questions.