Developer Tools
Format and Indent XML
XML Formatter for formatting, validating, or converting XML data.
Direct Answer
Use the XML Formatter when XML arrives as one long line from an API response, SOAP service, or export and you need to see the nested element structure to debug it. Paste the XML in and it reformats with consistent indentation without changing tags, attributes, or text content.
Why XML Needs a Single Root Element
Every well-formed XML document must have exactly one top-level element that contains all other content; unlike JSON, which can start with an array, XML always nests everything inside one root.
- A document with two sibling elements at the top level, like a and b tags side by side, is not well-formed until both are wrapped in one parent.
- The root element can have any name, such as root, data, or response, as long as there is exactly one.
- Formatting will not add a missing root for you; it usually fails or produces unreadable output on a document with no single root.
- SOAP, RSS, and most API XML already have a natural single root, so this rarely comes up outside hand-edited snippets.
Formatting vs Validating XML
Formatting only rearranges whitespace between tags and attributes so nesting is visible; it does not check the document against a schema or DTD, and it can succeed on XML that a strict validator would reject.
- A formatter confirms tags are well-formed enough to know where one ends and the next begins.
- It does not confirm a required attribute is present or that an element only appears where a schema allows it.
- Namespace prefixes are preserved as-is even when the matching xmlns declaration is missing.
- For contract or API compliance checking, pair formatting with a dedicated XSD or DTD validator.
How to Use XML Formatter
- Paste or type your content into the input box.
- The transformed result appears instantly in the result panel below.
- Click Copy result to copy the output to your clipboard.
- Download .txt saves the transformed text as a file.
- Reset clears everything and lets you start over.
Reference
| Feature | Details |
|---|---|
| Purpose | Transform pasted text into a cleaner or different format. |
| Input | Text, lines, lists, or copied content. |
| Result | Transformed text ready to copy or download. |
| Best for | Cleanup, formatting, list preparation, and copy-paste workflows. |
| Category | Developer Tools |
| Works on | Desktop, tablet, and mobile browsers |
Useful Related Tools
Frequently Asked Questions
Why do I get a root element is missing or multiple roots error?
XML requires exactly one top-level element that contains everything else; if your document has two sibling elements at the outermost level, such as two item tags not wrapped in a parent, it is not well-formed and most parsers reject it before attempting to format it. Wrap the siblings in a single wrapping element, such as items or root, to fix it.
What is the difference between well-formed and valid XML?
Well-formed XML follows the basic syntax rules of XML itself: one root element, matching open and close tags, quoted attribute values, and proper nesting. Valid XML is well-formed and additionally conforms to a specific schema or DTD that defines which elements, attributes, and structures are allowed; a formatter checks well-formedness, not schema validity.
Should I put data in an attribute or a child element?
There is no strict rule, but a common convention is to use attributes for metadata about an element, such as an ID, type, or unit, and child elements for the actual content, especially long or multi-line content. Attributes also cannot repeat on the same element and cannot hold structured sub-data, so anything that might need to expand into multiple values belongs as a child element instead.
Why does my formatter show escaped entities like < in the output?
Characters that are reserved in XML must be escaped in text content: an ampersand becomes &, a less-than sign becomes <, and a greater-than sign becomes >, because a raw less-than or ampersand would be read as the start of a tag or entity. If you see a doubly escaped entity instead of the decoded character, the value was encoded twice somewhere upstream, often during a data transfer step.
What is a CDATA section for?
A CDATA section tells the XML parser to treat everything inside it as plain text without interpreting angle brackets or ampersands as markup, which is useful for embedding HTML snippets, script code, or other markup-heavy content without escaping every special character. Formatting tools should leave CDATA content untouched internally, only adjusting the indentation around it.
Why did formatting change my self-closing tags?
An element with no content is functionally identical whether it is written as an open and close pair or as a self-closing tag, and many formatters normalize one style to the other for consistency. This does not change the data since it is a purely syntactic choice, but if you need to match an exact output format for a diff or another system, check whether the formatter has an option to preserve the original style.
What does the XML declaration line do, and can I remove it?
The line at the top of a document that looks like an xml version and encoding tag is technically optional, but omitting it means parsers assume UTF-8 or UTF-16 by default, so if your document uses a different encoding, leaving it out can cause characters to render incorrectly. Keep it if the original document had one, and make sure the declared encoding actually matches how the file is saved.
Can XML have more than one document in a single file?
Not the way YAML supports multi-document files with dashed separators; each XML file must have exactly one root element wrapping all content. If you need multiple records, wrap them as sibling child elements inside one root, such as a records element containing several record elements.