DEVELOPER TOOL

XML Formatter

Validate and format XML markup.

About XML Formatter

Machine-generated XML, such as an API response, a sitemap, an RSS feed or a configuration export, often arrives as one long line. Reading it that way is slow and error-prone. This tool parses what you paste and writes it back with a line break between neighboring tags, so the structure becomes visible at a glance. It is a practical first step before reading, diffing or debugging a document you did not write yourself.

The parsing is done by the browser's own DOMParser, the same engine that reads XML for web pages. If the text is not well-formed, the output box shows the message Invalid XML instead of a result. That makes the page useful as a quick check for unclosed tags, mismatched names, unescaped ampersands or a missing root element. Because this is the browser's standard XML parsing, results match what other web-based XML tools would accept as well-formed.

It is worth knowing exactly what the Format button does. It re-serializes the parsed document and inserts a newline between every closing and opening angle bracket. It does not add indentation, and it does not minify. Existing whitespace between tags is kept, so XML that was already indented will look much the same afterward. For deeper reformatting with indentation, use an editor that has a pretty-print command and treat this page as a quick checker.

How to use XML Formatter

  1. Copy the XML from your file, response or editor, including the root element and its closing tag. Leave out any text before the first opening angle bracket.
  2. Paste it into the large text box at the top of the tool. Make sure nothing is accidentally cut off.
  3. Click the Format button. The result appears in the box below the button.
  4. If the result reads Invalid XML, check for unclosed or mismatched tags, an unescaped & or <, or two root elements, fix the input and click Format again.
  5. Select the formatted output in the result area and copy it into your editor. Save the result back to your file or paste it into your next tool.

When this tool helps

Reading a one-line API response

When a web service returns XML without any line breaks, formatting it puts each tag on its own row. You can then scan for the field you want instead of searching through a single dense line. It is a small step that saves real reading time.

Finding why a file will not load

If an importer or parser rejects your file, paste the content here. An Invalid XML message confirms the problem is the markup itself, such as a stray ampersand, and not your application code. If it parses here, look elsewhere for the cause.

Reviewing a sitemap or feed

Before publishing a sitemap.xml or an RSS feed, run it through the parser to confirm it is well-formed. Line breaks make it easier to check that every URL entry has the tags you expect. This catches mistakes before readers or crawlers meet them.

Tidying config before a diff

Version control shows changes line by line. Putting elements on separate lines first makes a diff of two XML snippets far more readable than comparing two enormous lines. Comparing before and after becomes straightforward. It also helps when pasting snippets into a bug report.

Tips for better results

  • Escape special characters in text content. A raw ampersand must be written as &amp; and a less-than sign as &lt;, otherwise the parser reports an error.
  • Every XML document needs exactly one root element. Two sibling top-level elements are a frequent reason for the error message.
  • Tag names are case-sensitive, so Item and item are different elements. A closing tag must match its opening tag exactly.
  • If you paste a fragment such as a few sibling items, wrap them in a temporary root element first. Remove the wrapper afterward.
  • Check the output rather than assuming it is final. Text and attributes are kept as parsed, but the serializer may normalize things like empty elements or namespace declarations.

Good to know

  • The error message is just Invalid XML. It does not give a line number or column, so you may have to search the input yourself to find the faulty spot.
  • Output is not indented. Elements are placed on separate lines, but nesting depth is not shown with spaces, and there is no minify or sort option.
  • It checks well-formedness only. The XML is not validated against a DTD or an XSD schema, so a well-formed file can still be wrong for your application.

Privacy and your data

Parsing and formatting happen in your browser through its built-in XML parser. The markup you paste is not sent to any server.

XML Formatter FAQ

Does this XML formatter validate my XML?

It checks that the document is well-formed, meaning tags are properly nested and closed, there is one root element and special characters are escaped. It does not validate against a schema or DTD, so it cannot tell you whether the content is semantically correct.

Why does it only say Invalid XML?

The tool reports a general error when the browser parser fails, and it does not pass along the parser's position details. To find the problem, check for mismatched tags, missing quotes around attribute values, a raw ampersand, or a second root element.

Will it indent my XML?

No. It inserts a line break between adjacent tags but does not add leading spaces for nesting. If your input already contains indentation or line breaks, those stay as they were, so the output will look similar. For nested structure, use an editor with a pretty-print command.

Can it minify XML?

No. The Format button only adds line breaks. To shrink XML you would need to remove the whitespace between tags separately, for example with an editor's find and replace on the gaps between closing and opening brackets. Minifying also needs care around text content, where whitespace can matter.

What makes XML not well-formed?

Common causes are an opening tag that is never closed, tags closed in the wrong order, attribute values without quotes, unescaped ampersands or angle brackets in text, mismatched capitalization, and having more than one top-level element. Fixing these one at a time and reformatting usually clears the error.

Is my XML sent anywhere when I click Format?

No. The parse and the serialization both happen inside your browser tab. That makes it fine for internal configuration snippets, though you should still avoid pasting credentials into any web page out of habit. If you work with confidential data, remove anything sensitive before sharing screenshots of the output.

Browse all ELDOSA tools →