Cookies This site keeps only what it needs to work. There is no analytics and no advertising on it today, and nothing here follows you to other sites. Read the privacy policy

Choose what to allow
+92 312 8299940Free Quote
EN – Language: English
Free tool, works in your browser

XML Formatter
Tidy Indents, a One-Line Version and a Syntax Check

Paste messy XML into this XML Formatter and it will return formatted XML that is indented and readable, or help you locate the exact line that caused the error.

  • FreePrice
  • Line and columnChecks
  • NoneSign-up
  • In your browserRuns

XML Formatter

Format, minify and validate XML, with every error on its line

Elements
0
Depth
0
Size
0 B

Ready. Paste your XML, open a file or try the sample.

Your browser does all of the work here, in this tab. We upload nothing, store nothing and log nothing.

Run it on a test page before the live one

Keep a copy of your original code and try the result on a test page before you replace the live file. No automatic tool can see every way your site uses its code.

Add a link to this tool on your own site

Copy the code below and drop it into your page. It places a link to this free tool.

The basics

Jobs This XML Formatter Handles for You

This XML formatting tool will take XML files, regardless if they are on one single long line, or indented in five different ways, and arrange them nicely, just like a "pretty print" version of that file. It puts each element on its own line, moves each child to the right, and keeps short pieces of text next to their tags. The resulting layout is easy to understand visually, with a quick glance.

This tool also acts as a validator for XML well-formedness. Before formatting any document, it validates every single tag, attribute, and entity. If there are validation errors, you will be presented with the line number and column number where the error occurred, along with a simple description of the error and a link that allows you to position your cursor directly over the error.

The Denwix formatter does not transmit any of the XML to another location. As a result, your configuration files, feeds, and API responses are always contained within your own device, and so your keys, prices, and/or customer data are never exposed to others.

What Formatting Actually Changes

Formatting touches nothing but the spacing between tags. The names, the attributes, the text and the order of everything stay exactly as they were. A program that reads the file sees the same data before and after, so you can format with confidence.

Diagram of one long line of XML turned into indented XML, with each nesting level shifted to the right
The minifier does not change any values in the document. It only modifies the space between tags.

The rules follow the W3C XML specification, the standard every XML reader is built on. That is also why the checks are strict: a file that passes here will open in any tool that follows the same rules.

Format XML Without Losing Anything

Many formatters will quietly lose comments, CDATA sections or DOCTYPEs, as they were not designed to retain them by their parser. But this formatter retains all of these items. Your comments are retained exactly as you created them and the content of CDATA blocks is preserved.

XML formatter turning a one-line product feed into indented XML, keeping the comment and the CDATA section
Comments, CDATA and mixed text survive formatting unchanged.

Two cases will get special treatment. Elements containing the attribute xml:space="preserve" will be copied verbatim by the formatter (including all spaces and newlines). Also, elements that contain both text and tag content (e.g., a paragraph containing a bolded word) will remain formatted on a single line, as they were originally written, because creating extra lines within those elements would alter the text.

An XML Validator That Points to the Line

Knowing a file is damaged is just one-half of what needs to be accomplished. The checks table has all of the problems identified with their line number and column position: matching tags that do not have the same name; attributes that do not have quotes around them; a single ampersand; or a second root element. All of these problems are followed by a sentence which gives the solution.

XML validator listing a mismatched closing tag and an undefined entity, each with its line and column
Each problem has a line, a column and a plain explanation.

Click "Show me where," and the cursor will jump to the first error in your XML file. One error often leads to another, so if you fix the first error, and check again, you should be able to clear multiple errors simultaneously.

Shrink XML Into a Single Compact Line

You can choose the One line (minified) option from the indentation menu and the tool will compress your XML to one line. The whitespace between tags will be removed, but the text will maintain its words, and spaces that were multiple will now only have one. A switch allows you to either retain or remove any comments.

The same XML minified onto one line, with the checks table reporting how much smaller the file became
Minify in one step and see how many bytes you saved.

The checks table displays the size of the XML file before and post-load. While you typically prefer the formatted version of the XML file as you are working on it, smaller XML files load faster into feeds and API responses.

Why Well-Formed XML Can Still Fail Validation

XML users employ two similar-sounding terms: "well-formed" and "valid." "Well-formed" indicates a file adheres to the basic rules of XML, and every program reading it needs this. On the other hand, "valid" indicates a file conforms to a schema (e.g., XSD), which defines what elements can exist in a specific format. The tool described here will verify the former (i.e., the first criterion) for all files.

How the XML Validator Reads Your File

The XML validator will read through your file from beginning to end like a very strict parser. It will make sure that the declaration is at the top of your document, that all names begin with a letter, that each attribute is quoted, and that there are no duplicate attributes on any single tag.

Afterwards, the nesting follows. Each opening tag awaits its counterpart, and the validator indicates which tags close in an incorrect sequence or do not close at all. Lastly, the validator examines each ampersand and each entity because entities and ampersands create more damaged feeds than anything else. Since the validator reads rather than makes educated guesses, files that successfully pass through the validator will also successfully pass into the software that needs them.

Frequent XML Errors and Their Fixes

The most common mistake is writing an ampersand alone, like "Tom & Jerry." Because the ampersand is reserved by XML, you need to use & rather than just an ampersand. Similarly, if you have a less than symbol in your text, you will need to replace it with <. Finally, XML does not recognize any of the HTML entity references, including  . So, if you wish to use a non-breaking space, you should use  .

Next come tags that close in the wrong order and attributes without quotes. Names also matter, since XML is case sensitive and a closing tag must match its opening tag letter for letter. Namespaced names such as xs:element are fine, and the namespaces recommendation explains how those prefixes work.

Places XML Is Still Everywhere

XML is older than JSON, yet it is everywhere. Sitemaps, RSS and Atom feeds, SVG images, Office documents, Android layouts, Maven and .NET project files, SOAP services and many bank and government interfaces all use it. For a gentle overview, MDN’s introduction to XML is a good start.

Our XML to JSON converter converts your data to JSON format in a single operation if you have a need for that data elsewhere. If the data being converted is a sitemap, the sitemap generator can create a correctly formatted sitemap based on a list of URLs.

Video guide

See the XML Formatter at Work, Start to Finish

This brief video shows each step from start to finish. Choose your language below, and switch on captions if they help.

Four steps

How to Format XML

When most files have already been formatted when you finish reading this sentence, because the output is visible as soon as you begin typing.

  • Paste the XML, or load it from a file

    Paste the XML into the Denwix input box, open a file, or drop one onto the box.

  • Pick the indent

    Two spaces, four spaces, tabs, or one line if you want it minified.

  • Repair each problem the checks list

    Every problem shows its line and column. Show me where jumps straight to the first one.

  • Copy or download

    Copy the tidy XML, or save it as a file ready to use.

Why this one

Built for Real XML Files

A quick way to format XML is easy to build. These details make it safe to trust.

  • Nothing is dropped

    Comments, CDATA, the DOCTYPE and instructions all stay in place.

  • Errors on their line

    Every problem shows its line and column, with a jump button.

  • Whitespace respected

    xml:space="preserve" and mixed text are kept exactly as written.

  • Format or minify

    Two spaces, four, tabs, or one compact line, in the same box.

  • Long tags wrapped

    Tags with many attributes can put each one on its own line.

  • Private by design

    Once loaded, the page keeps working offline and uploads nothing.

Good habits

Rules That Apply To Every XML File

The XML validator above, just like all strict readers, will flag the file if you break any of these.

  • One root element. All of your HTML must reside within a single parent element. You cannot have two separate elements on the same level (horizontally) as the root element.
  • Close every tag. Each opening tag needs a closing tag, or it must close itself, as in
    .
  • Nest in order. Tags must close in the opposite order to how they opened. is broken.
  • Quote every attribute. Use id="7" or id='7', never id=7.
  • Escape & and <. Write & and < in text and attribute values.
  • Match the case. and are two different names, so they do not close each other.
  • Put the declaration first. If you include the line, nothing may come before it in the file.
  • Name attributes once. An element cannot carry the same attribute twice.
Common slips

Six XML Mistakes to Avoid

Each one stops a feed, a config or an import from loading.

  • Pasting HTML entities

      and © work in HTML but not in plain XML.

  • Hand-editing a long line

    Format first, edit second. Mistakes hide easily in one long line.

  • Text before the declaration

    Even one space or an invisible BOM before

  • Formatting mixed content by hand

    Line breaks inside a sentence with tags change the text itself.

  • Trusting a lenient reader

    Browsers forgive a lot, but feed and API readers usually do not.

  • Mixing up the encoding

    A file that says ISO-8859-1 but is saved as UTF-8 garbles accents.

Questions

XML Formatter: Your Questions

What steps tidy my XML on Denwix?

The user will then paste the XML into the Denwix input box. As they type, the indented XML will fill the output panel so that they can either copy or save it.

Will the formatter alter any of my values?

No. The minifier touches nothing but the gaps between tags. Names, attributes, text and order all stay the same.

Can I use it as an XML validator?

Yes. It will check if the file is well-formed, and list all problems (with their respective lines and columns).

Does the formatter keep comments and CDATA sections?

Yes. Comments, CDATA sections, DOCTYPE and processing instructions remain at their original locations.

What steps shrink my XML to one line on Denwix?

Choose One line (minified) in the indent menu. After that, you will see how much smaller your file has become in the check marks table.

Why does it say my ampersand is wrong?

XML reserves the ampersand for entities, so a plain one must be written as an entity too. The section on common errors above shows how.

Why is the non-breaking space entity an error?

HTML defines it, but XML does not. Use the numeric entity for character 160 instead, or declare the name in a DOCTYPE.

Will the formatter check my XML against an XSD schema?

No. It checks that the file is well formed, which every XML file needs. Schema checks need the schema file too.

Will it format SVG, RSS or sitemap files?

Yes. Underneath they are plain XML, so formatting and validation work the same.

What is the biggest XML file the Denwix formatter takes?

Files of a few megabytes go through fine. Above 400 KB, it formats when you press Format instead of on every key.

Why does the validator stop at a < sign?

A less-than sign always starts a tag in XML, so text cannot contain one on its own. Escape it as an entity, or put the text inside a CDATA block.

Can it fix my XML for me?

It points to each problem instead of guessing, since a guess could change your data. Most fixes take a second once you see the line.

Does the Denwix formatter send my XML anywhere?

No. Your browser does the formatting, so no server sees the XML.

More free tools

More Tools for Data and Code

Handy next steps once your XML reads cleanly.

Ready to Tidy Your XML?

You can simply paste your XML into the box below, and a clean version will appear instantly. Our XML formatter is free, needs no user account, and runs directly within your web browser.

Prefer Denwix on GoogleReview Denwix on Google