XML Formatter | Beautify
text / xml XML Formatter
Format, indent, and minify XML in your browser. Paste a document to pretty-print it with nested elements indented, collapse it back to a single line, or sort attributes for easier comparison. Structural problems such as mismatched or unclosed tags are reported with a line and column. Nothing is uploaded — SOAP envelopes, configuration files, and feeds stay on your device.
What the actions do
Beautify
Re-indents each level of nesting by two, four, or eight spaces. Elements whose entire content is a short piece of text stay on one line, because breaking <title>Report</title> across three lines makes it harder to read rather than easier. Comments, CDATA sections, and the XML declaration are preserved exactly.
Minify
Strips the whitespace between elements while leaving text content intact. Useful when embedding a document in a request body or a configuration value where size matters. Note that whitespace inside an element is sometimes significant, so minifying is not always safe for mixed-content documents such as XHTML.
Sort attributes
Orders each element's attributes alphabetically. Attribute order carries no meaning in XML, so two documents that differ only in ordering are equivalent — but a plain text diff will show them as different. Sorting both first reduces the comparison to real changes.
Well-Formed versus valid
Well-formed means the document obeys the syntax in XML 1.0: tags nest, every element closes, attribute values are quoted. Valid is a stronger claim — that it also conforms to a schema or DTD saying which elements may appear where. This tool checks the first and not the second. Prefixes such as xsd: are resolved through XML Namespaces, so the same element can carry different prefixes in two documents and still be the same element.
These are different things, and the distinction matters when a parser rejects your document. This tool checks the first:
- Well-formedmeans the syntax is correct — every element is closed, tags nest without overlapping, attribute values are quoted, and there is a single root element. Any XML parser will reject a document that is not well-formed.
- Validmeans the document also conforms to a schema — an XSD, a DTD, or a RELAX NG grammar — which specifies which elements may appear, in what order, and with which attributes. A perfectly well-formed document can still be invalid against its schema.
Common uses
- Reading a SOAP response.Web service responses arrive as one continuous line; indenting them is the quickest way to find the element you actually want.
- Editing configuration.Maven
pom.xmlfiles, Android layouts, Spring bean definitions, andweb.configare all XML that becomes unreadable when indentation drifts. - Inspecting an RSS or Atom feed.Feeds are published minified; formatting reveals the structure of the entries.
- Checking an SVG.SVG is XML, so exported graphics can be tidied and inspected here.
- Comparing two documents.Beautify both with the same indent and sort their attributes before diffing.
Things that trip people up
- XML is case-sensitive.
<Item>and<item>are different elements, and closing one with the other is an error. HTML is forgiving about this; XML is not. - Every element must be closed.There is no equivalent of HTML's bare
<br>. Write<br/>instead. - Tags cannot overlap.
<a><b></a></b>is never legal, however common it is in hand-edited markup. - Five characters need escaping.
&,<,>,"and'become&,<,>,"and'. A bare ampersand in a URL inside an attribute is a frequent cause of parse failures. - There can be only one root element.A document with two top-level elements is a fragment, not an XML document, and parsers will refuse it.
Frequently asked questions
Does formatting change my document?
Does this validate against a schema?
Can it handle namespaces?
<soap:Envelope> are treated as ordinary element names and pass through untouched, as do xmlns declarations. The formatter does not resolve prefixes to their URIs, because it is not doing anything that requires it.What about HTML?
<img> and <br> are unclosed by design, and browsers accept unquoted attribute values, so this tool will report an ordinary HTML page as not well-formed. XHTML, which was written to XML rules, works.Is my XML uploaded anywhere?
Standards and references
- XML 1.0 (5th ed.) Extensible Markup Language (XML) 1.0 2008
- XML Namespaces 1.0 Namespaces in XML 1.0 (Third Edition) 2009