XML Formatter and Validator
Check XML syntax and format a well-formed document.
What Is an XML Formatter and Validator?
An XML formatter and validator helps you inspect structured XML markup, make nested elements easier to read, and identify syntax problems such as mismatched tags or unescaped characters. Formatting organizes the text; a well-formedness check examines whether it follows XML syntax rules. That is different from validating an XML document against an XSD or DTD schema. Use the tool to review XML before importing data, editing feeds, troubleshooting configuration files, or examining XML sitemaps.
XML Formatter and Validator
Check XML syntax and format a well-formed document.
Read, Format, and Troubleshoot XML Without Changing Its Meaning
XML is still widely used in search-engine sitemaps, RSS and Atom feeds, WordPress exports, web-service messages, and configuration documents. A compact XML file can be difficult to inspect because the hierarchy is hidden in long lines of markup. Indentation makes parent and child elements visible, while XML parsing can expose errors that prevent an application from reading the document at all.
Start with a copy of the original XML. Enter a short representative sample into the formatter and review the available results or error messages. Do not assume that the page supports file uploads, downloads, XSD validation, or local-only processing until those features are confirmed in the deployed tool. The examples below show what to look for and how to interpret common problems, whatever interface you use.
Read Full GuideShow Less
What XML Formatting Changes and What It Must Preserve
Extensible Markup Language, or XML, represents information as nested elements with optional attributes and text. The document has exactly one root element, and every start tag must have a matching end tag unless it uses the empty-element form. A formatter generally adds line breaks and indentation so you can follow the hierarchy. Those visual changes should not be confused with repairing missing data or checking that the document meets a particular application’s requirements.
Compare this compact sample with its indented form. Both express the same simple element hierarchy:
<catalog><item id="17"><title>Blue notebook</title><price>9.50</price></item></catalog>
<catalog>
<item id="17">
<title>Blue notebook</title>
<price>9.50</price>
</item>
</catalog>
The example uses two-space indentation, but a developer may choose another style. The important part is making nesting consistent. Real-world XML can contain significant whitespace, so a format-and-save operation is not automatically safe for every document. Always compare text values if the file mixes words with inline elements.
Well-Formed XML Is Not the Same as Schema-Valid XML
An XML parser checks basic syntax, including element nesting, allowed names, quoting, and properly formed character references. Passing that check means the document is well-formed. A second, optional level of checking uses a document type definition (DTD) or an XML Schema Definition (XSD) to enforce rules such as which elements are allowed, what order they appear in, and whether a particular value must be an integer.
| Check | What it answers | Example |
|---|---|---|
| Formatting | Is the source arranged for easier reading? | Indent nested item elements |
| Well-formedness | Can an XML parser read the markup? | All opening tags close correctly |
| DTD or XSD validation | Does the document satisfy a defined vocabulary and constraints? | A price must be a decimal according to the schema |
| Application checks | Can the target system use the document as intended? | A sitemap has usable canonical URLs |
A well-formed <price>banana</price> element is possible XML, even if a store’s schema requires decimal numbers. A generic syntax validator cannot determine those business rules. Only claim XSD or DTD support when the actual tool offers it and accepts the required schema.
Find the First XML Syntax Error Before Fixing Everything Else
XML parsing often stops at the first fatal error, and later error locations may be consequences of the initial problem. Work from the earliest reported line or character offset. Look for a closing tag that uses the wrong name, a missing quote, an unescaped ampersand, or content outside the root element. XML names are case-sensitive, so <Entry> and <entry> are different names.
For example, this markup has an incorrectly nested closing tag:
<feed><entry><title>Update</entry></title></feed>
Close the title element before closing entry:
<feed><entry><title>Update</title></entry></feed>
If a large file fails, isolate the smallest affected element, correct it, and rerun the check. Do not assume that a formatter will safely rewrite malformed source into the intended structure without your review.
Escape XML Characters Correctly, Especially in URLs
XML treats some characters as markup. In ordinary element text, a literal ampersand must be written as &, and a literal less-than character must be written as <. In attribute values, the quote character matching the attribute delimiter also needs escaping. The predefined entity references include &, <, >, ", and '. Do not assume that HTML-only entities such as are predefined in XML.
A common problem appears when adding a URL with multiple query parameters to a feed or sitemap. The URL may legitimately contain an ampersand, but XML text must escape it:
<url>
<loc>https://example.com/products?color=blue&size=large</loc>
</url>
When parsed, the loc element’s text contains the ordinary URL with an ampersand. The XML source is encoded for XML syntax, not necessarily URL-percent-encoded. For actual percent-encoding tasks, use the URL Encoder and Decoder and distinguish the two operations.
Understand XML Namespaces Before Editing Sitemaps and Feeds
Namespaces prevent collisions between element vocabularies. A default namespace is introduced with xmlns, while a prefix is bound using a declaration such as xmlns:media. The prefix is an alias for a namespace identifier; it is not inherently meaningful by itself. A prefixed element with no declared prefix causes a namespace-aware parse error.
This is a small example of a declared prefix:
<feed xmlns:media="https://example.org/media-schema">
<media:thumbnail>cover.jpg</media:thumbnail>
</feed>
Do not rename or strip namespace declarations just to shorten the source. They determine how software interprets the element names. For XML sitemaps, use the vocabulary and namespaces required by the sitemap protocol rather than relying solely on a generic XML syntax check.
Inspect XML Sitemaps for More Than Proper Nesting
Search engines consume XML sitemaps as a specific document format. A sitemap can parse correctly yet still contain a wrong namespace, missing URL values, inappropriate address formats, or other sitemap-level issues. Google’s documentation requires a UTF-8-encoded sitemap file, absolute URLs, and correctly escaped data. A standard sitemap uses the urlset element and the sitemap protocol’s namespace.
Here is an illustrative minimal sitemap document:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://example.com/articles/</loc>
</url>
</urlset>
The XML declaration, element nesting, and namespace can be inspected in a formatter. To check sitemap-specific requirements separately, use the XML Sitemap Validator. If you are creating a new sitemap rather than troubleshooting one, the XML Sitemap Generator addresses the earlier step in that workflow.
Know When Whitespace and CDATA Can Change Meaning
XML whitespace inside text nodes can be meaningful. Consider <p>Read <strong>this</strong> first</p>: adding line breaks between words and child elements may change the text presented by the consumer. The xml:space attribute can communicate a whitespace-preservation intention, but an editor or parser’s behavior must still be evaluated for the application.
A CDATA section stores character data that would otherwise need escaping. For example, <![CDATA[one & two]]> represents text containing an ampersand. The sequence ]]> ends a CDATA section, so it cannot appear literally inside that section. Formatters must be careful not to break text payloads, CDATA boundaries, significant whitespace, or entity references.
If a formatter rewrites a mixed-content document, use a before-and-after comparison of parsed text as well as source. Pure indentation does not guarantee semantic equivalence for every XML vocabulary.
Handle XML Declarations, Encodings, and Comments Carefully
An XML declaration, when present, belongs at the beginning of the document. Its encoding value should agree with the actual bytes when the file is saved. A browser textbox displays characters, not necessarily the original file’s byte encoding, so copying a snippet into a new document can introduce an encoding mismatch if the destination editor uses a different charset.
XML comments use <!-- ... -->. The double-hyphen sequence is not allowed inside a comment. Attribute values must be quoted, and the same attribute name cannot appear twice on a single element. Unlike forgiving HTML parsers, XML parsers generally reject these mistakes rather than silently rearranging the markup.
Review WordPress XML Exports and RSS Feeds Before Importing
WordPress export files use XML to describe content and metadata. They may contain namespaced fields, embedded HTML inside CDATA, and large text values. An XML formatter can help you locate the element that contains a post title or a field, but it does not replace a WordPress-specific import test. Preserve export structure, content payloads, and namespaces while diagnosing problems. The WordPress XML Export Inspector is a more targeted companion tool for that file type.
RSS and Atom feeds are also XML-based but follow their own specifications. A file may be well-formed and still lack required feed elements or contain invalid dates. The RSS and Atom Feed Validator is more appropriate for feed-level checks than indentation alone.
Troubleshoot Failed Formatting or Unexpected Output
| Symptom | Likely cause | Next check |
|---|---|---|
| Mismatched end-tag error | Incorrect nesting or capitalization | Compare the nearest opening and closing tags |
| Unexpected ampersand | Unescaped text character | Replace literal text ampersands with & |
| Unbound namespace prefix | Missing xmlns:prefix declaration |
Restore the correct namespace binding |
| XML declaration error | Unexpected characters before the declaration | Check the beginning of the source and file encoding |
| Sitemap parses but is rejected | Sitemap-specific requirement not met | Check namespaces, required tags, URL format, and Search Console errors |
| Text content changes | Mixed-content whitespace was modified | Restore from the original and compare parsed text |
When multiple issues appear, fix the first confirmed syntax error rather than guessing at later messages. A cleanly formatted file may still be unsuitable for the target application, and a validator’s success message should be interpreted according to exactly which check was performed.
Protect Untrusted and Confidential XML
XML files can contain customer records, internal identifiers, private URLs, access tokens, and configuration secrets. Remove sensitive values before placing XML in an unfamiliar service. Do not assume that submitted text stays in the browser or is deleted automatically unless the tool’s implementation and policies have been reviewed.
There is also a distinct XML external entity (XXE) security risk when software processes untrusted input with unsafe external-entity resolution. Developers should disable unneeded DTD processing and external resource resolution and apply resource limits. Formatting a document does not by itself neutralize an unsafe downstream parser. The appropriate safeguards belong in the application that consumes XML.
Questions About XML Formatting and Validation
Can an XML formatter fix broken XML automatically?
Some products can suggest repairs, but there is no universal safe automatic correction. A missing tag can represent different intended structures. Fix the markup based on the source data and inspect the result.
Why does valid-looking XML fail an XSD check?
It may be well-formed but violate schema rules for element order, required attributes, datatypes, or namespaces. Use the exact schema required by the consuming application to investigate.
Is XML formatting the same as minifying XML?
No. Formatting typically adds whitespace to improve readability. Minification generally removes selected whitespace. Both operations can change meaningful text in some XML documents, so verify the output.
Can a generic XML checker validate my Google sitemap?
It can help detect XML syntax errors, but sitemap-specific checks are separate. Confirm the sitemap namespace, tags, URLs, file limits, and any reported Search Console processing problems.
Is XML different from HTML when closing tags?
Yes. XML requires strict, properly nested element markup, and empty elements may be written as <tag/>. HTML follows different parsing rules and allows certain omitted end tags.