XML Formatter & Validator
Pretty-print, minify and validate XML, then test XPath. Runs in your browser.
About this xml formatter & validator
This XML formatter pretty-prints or minifies XML and tells you whether it is well-formed, with the exact line and column of the first problem. It also runs XPath queries against your document, so you can check what `//order/item[@sku]` really matches before you put it in code.
Attribute quotes, entities like &, CDATA sections and comments come out exactly as you wrote them. Elements that mix text and tags, and anything marked xml:space="preserve", keep their original spacing so the formatter never changes your data.
It works on SOAP responses, RSS and Atom feeds, sitemaps, SVG, Android layouts, Maven pom.xml files, .csproj files and KML. All of it runs in your browser; nothing is uploaded.
Features
Two checks, not one
Our own parser checks nesting, quoting, entities and the single-root rule and points at the exact character. Then your browser's XML parser gives a second opinion, which catches undefined entities such as and namespace prefixes nobody declared.
Formatting that keeps your text intact
Whitespace-only gaps between tags are re-indented. Real text is left alone, and an element that mixes text with tags, like <p>Hello <b>you</b></p>, stays on one line so no spaces are added inside your content.
Minify for transport
Minify strips the indentation between tags and can drop comments. The badge shows how much smaller the result is.
XPath 1.0 tester
Type an expression and see every match: elements, attributes, text nodes, or a number, string or boolean for functions like count() and sum(). Default namespaces get the prefix d: so queries still work on namespaced feeds.
Options that matter
Indent with 2 spaces, 4 spaces or tabs, put each attribute on its own line, and write empty elements as <a/>. The address bar remembers the mode, indent and query, never the XML.
How to use the xml formatter & validator
- 1Paste XML or open a file. It is checked and formatted straight away.
- 2Choose Format or Minify and the indent, then fix any error the checker points to.
- 3Copy or download the result, or type an XPath query to see what it matches.
When to use it
Reading a SOAP or API response
Paste the one-line response from your logs and get an indented tree you can scan. Then query `//d:Fault` to see if the service returned an error.
Fixing a sitemap or feed that fails to load
Search engines and feed readers reject files with a stray & or an unclosed tag. Find the line here, fix it, and check the rest with the XML Sitemap Generator if you are building one from scratch.
Cleaning up exported SVG
SVG is XML. Format it here to read it, then shrink it with the SVG Optimizer or turn it into a React component with the HTML and SVG to JSX converter.
Building an XPath for a scraper or test
Try expressions against a real document until the match count is right, then copy the expression into Selenium, Playwright, lxml or XSLT.
What makes XML well-formed?
The XML 1.0 specification from the W3C sets a short list of rules. A document that breaks any of them is not XML at all, and a strict parser stops at the first error:
- Exactly one root element wraps everything else.
- Every start tag has a matching end tag with the same name and case, or is self-closing like <br/>.
- Tags close in the reverse order they opened: <a><b></b></a>, never <a><b></a></b>.
- Attribute values are always quoted, and one attribute name appears only once per element.
- A raw < or & in text must be written < or &. Only five entities are built in: < > & " '.
- The XML declaration, if present, comes first: <?xml version="1.0" encoding="UTF-8"?>.
Well-formed vs valid XML: what is the difference?
Well-formed means the syntax is correct. Valid means the document also follows a schema (an XSD, DTD or RELAX NG file) that says which elements may appear where. A purchase order can be perfectly well-formed and still invalid because it is missing a required <customerId>.
This tool checks well-formedness. Schema validation needs the schema file and a validating parser, which browsers do not include, so use your build tool or an IDE such as IntelliJ or VS Code with an XML extension for that step.
How do XPath queries work?
XPath describes a path through the tree. `/catalog/book` starts at the root, `//title` finds title elements at any depth, `@id` selects an attribute, and square brackets filter: `//book[price < 20]` keeps cheap books only. Functions return values instead of nodes, so `count(//book)` gives a number.
Browsers implement XPath 1.0, the 1999 W3C version used by XSLT 1.0, Selenium and most scraping libraries. Newer XPath 2.0 and 3.1 functions such as matches() or tokenize() are not available here.
Namespaces trip people up. In XPath 1.0 an unprefixed name never matches an element in a default namespace, so `//item` finds nothing in an Atom feed. The tool maps the root's default namespace to d:, so `//d:entry` works.
Why use Mavros
| Mavros | Typical upload sites | |
|---|---|---|
| Where your XML goes | Stays in your browser | Often uploaded, sometimes saved behind a share link |
| Error location | Line, column and a jump to the character | A generic 'invalid XML' message |
| Mixed content and CDATA | Kept byte for byte | Whitespace often added inside text |
| XPath | Built in, with namespace help | A separate page, or missing |
| Entities and quotes | Written exactly as in the source | Often re-encoded |
Tips
- If the browser's parser complains about or ©, those are HTML entities. Use   and © in XML, or declare them in a DTD.
- Switch on One attribute per line before you diff two config files. Each attribute change then shows as its own line in a text diff.
- To move data out of XML into JSON or CSV, the JSON, CSV, YAML and XML converter handles the conversion.
- Large exports format faster from Open file than from a huge paste.
Questions
How do I format XML online?
Paste the XML into the input box and the indented version appears on the right straight away. Choose 2 spaces, 4 spaces or tabs, then copy it or download it as a .xml file.
How do I check if my XML is valid?
Paste it in and read the badge: Well-formed XML or Not well-formed. Errors give the line and column. For validity against an XSD or DTD you need a validating parser in your IDE or build, which browsers do not provide.
Why does my XML fail with an error about &?
Because a bare ampersand is not allowed in XML text or attributes. Write & instead, or wrap the text in a CDATA section. Names like also fail unless a DTD defines them.
Does formatting change my XML data?
No. Only the whitespace between tags changes. Text, attribute values, entities, comments and CDATA stay as written, and elements with mixed content or xml:space="preserve" keep their exact spacing.
Which XPath version does it support?
XPath 1.0, the version built into every major browser. Axes, predicates and functions such as count(), contains(), starts-with() and normalize-space() work; XPath 2.0 functions like matches() do not.
Why does my XPath return nothing on a feed or SOAP message?
The elements are probably in a default namespace. XPath 1.0 cannot match those by bare name, so add the prefix d: (for example //d:entry), or use //*[local-name()='entry'].
Can it handle large XML files?
Files of a few megabytes format in well under a second on a typical laptop. Very large exports can make the page slow while it formats, so use Open file rather than pasting.
Is my XML uploaded anywhere?
No. Parsing, formatting and XPath all run in your browser tab. The address bar keeps only your mode, indent and query.