PublicSoftTools
Tools16 min read·PublicSoftTools Team·May 2026

XML Formatter — Format, Validate, and Pretty Print XML

XML (eXtensible Markup Language) is used for configuration files, API responses, data exchange, RSS feeds, SOAP web services, and document storage. XML sent over a network or stored in files is often minified — all on one line, impossible to read. The XML formatter on PublicSoftTools instantly formats XML into indented, human-readable output and validates the structure for errors.

How to Format XML

  1. Open the XML formatter.
  2. Paste your XML into the input panel — minified, single-line XML works fine.
  3. Click Format. The formatter parses the XML and outputs it with consistent indentation (2 or 4 spaces, selectable).
  4. Any XML errors are highlighted with the line and character position, and a description of the problem.
  5. Use Minify to remove all unnecessary whitespace and produce compact XML for transmission.
  6. Copy the formatted or minified output.

XML Structure Reference

Element typeSyntaxPurpose
Declaration<?xml version="1.0" encoding="UTF-8"?>Optional first line of XML document. Specifies XML version and character encoding.
Element (tag)<tagName>content</tagName>The fundamental unit of XML. Has a start tag, content, and end tag. Case-sensitive.
Attribute<element attr="value">Name-value pair within a start tag. Values must be quoted (single or double).
Self-closing element<element />Element with no content. Shorthand for <element></element>.
Text content<name>John Smith</name>Character data between start and end tags. The actual content of an element.
Comment<!-- This is a comment -->Human-readable notes not processed by parsers. Cannot contain --.
CDATA section<![CDATA[raw text & <tags>]]>Blocks of text where < and & do not need escaping. Used for embedded code or raw text.
Namespace<ns:element xmlns:ns="uri">Avoids element name conflicts when combining XML from different vocabularies (e.g., SOAP+XML).

Common XML Errors and Fixes

ErrorExampleFix
Unclosed tag<name>John</nam>Every start tag must have a matching end tag with identical name: </name>
Unescaped special charactersPrice: 5 < 10Escape: < → &lt; > → &gt; & → &amp; " → &quot; ' → &apos;
Wrong case on tag names<Name>text</name>XML is case-sensitive — <Name> and <name> are different tags. Must match exactly.
Unquoted attribute values<el attr=value>All attribute values must be quoted: attr="value" or attr='value'
Multiple root elements<a>x</a><b>y</b>XML documents must have exactly one root element that wraps all others.
Invalid characters in names<2element> or <el-em>Element names must start with a letter or underscore, not a digit or hyphen. Hyphens allowed after first character.

Well-Formed vs. Valid XML

There are two distinct concepts in XML correctness:

The XML formatter validates well-formedness — it will catch syntax errors. Schema validation requires the schema file (XSD or DTD) alongside the XML, which is a separate tool. For most purposes (APIs, config files, debugging), well-formedness validation is what is needed.

XML Special Characters and Escaping

Five characters have special meaning in XML and must be escaped when they appear in text content or attribute values:

A CDATA section (<![CDATA[...]]>) allows any content without escaping — useful for embedding JavaScript, HTML, or SQL inside XML without converting every < and &.

XML in APIs: REST vs. SOAP

XML was the dominant data format for web APIs throughout the 2000s, particularly in SOAP (Simple Object Access Protocol) web services. It has largely been replaced by JSON for REST APIs due to JSON's more compact syntax and native JavaScript support. However, XML is still widely used:

XML vs. JSON: When to Use Each

Choosing between XML and JSON depends on the use case:

XPath: Querying XML

XPath is a query language for selecting nodes in XML documents. It is to XML what CSS selectors are to HTML. Common XPath expressions:

XPath is used in XSLT (transforming XML to other formats), test automation (Selenium locators), and XML processing libraries.

Common Questions

What does well-formed XML mean in practice?

Well-formed XML means a parser can read it without errors. The key rules: one root element wrapping everything; all tags are closed (either <tag>...</tag> or <tag />); tags are properly nested (no overlapping — <a><b></a></b> is invalid); attribute values are quoted; five special characters are escaped. If an XML document is not well-formed, XML parsers throw an error and refuse to process it.

Can XML have mixed content?

Yes — XML supports mixed content: elements containing both text and child elements. Example: <p>This is <em>important</em> text.</p> — the <p> element contains both a text node and an <em> child element. This is common in document-centric XML (HTML-like content). Schema definitions must explicitly allow mixed content in the element declaration.

What is the difference between XML and HTML?

HTML (HyperText Markup Language) and XML look similar but serve different purposes and have different rules. HTML has fixed tags with defined meanings (<p>, <div>, <img>); XML tags are custom (you define them). HTML browsers are lenient — they attempt to display malformed HTML. XML parsers are strict — malformed XML is an error. XHTML was an attempt to make HTML conform to XML rules. Modern HTML5 and XML coexist as separate standards; they are not versions of the same language.

Format Your XML

Paste any XML — minified or malformed — and get instant formatted, indented output with error highlighting. Free, no signup.

Open XML Formatter