Skip to content

XML Validator

Result —
First error
—
Error line
—
Error column
—
Root element
—
Elements
—
Nesting depth
—
Lines
—

Paste XML and the validator checks it against the XML 1.0 well-formedness rules: one root element, strictly nested tags, quoted and unique attributes, and escaped ampersands and less-than signs. For an element a that holds an open element b and is closed before b, it reports Not well-formed at line 1, column 7.

About this tool

A feed that will not import, a config file a service refuses, or an SVG that renders blank often comes down to one broken tag. This validator reads your XML the way a parser does and stops at the first rule it breaks, naming the problem and giving its line and column so you can jump straight to it. When the document passes, it reports the root element, how many elements it holds, how deep they nest, and which element names appear most often. It checks well-formedness only: it does not validate against a DTD or XML Schema, so a document can pass here and still be rejected by a system that expects particular elements. The text stays in your browser.

How to use it

  1. Add the XML

    Paste the document into the box or open an .xml, .svg or .txt file from your device.

  2. Read the verdict

    The result shows Well-formed or Not well-formed and updates as you edit.

  3. Go to the error

    Use the line and column figures to find the first problem, fix it, and the check runs again.

  4. Review the structure

    For a valid document, the table lists element names by how often they occur.

Examples

Overlapping tags

XML document
<a><b></a>

Result Result: Not well-formed
First error: Expected </b> but found </a>.
Error line: 1
Error column: 7
Root element: —
Elements: 0
Nesting depth: 0
Lines: 1

  1. Scanned tags, attributes, comments, CDATA and entity references against the XML 1.0 syntax rules.
  2. Stopped at line 1, column 7: Expected </b> but found </a>.

The b element is still open when the end tag for a arrives. XML requires strict nesting, so the check stops at column 7.

A small note document

XML document
<?xml version="1.0"?> <note id="7"> <to>Ana</to> <from>Omar</from> <body>Tea & cake at 5</body> </note>

Result Result: Well-formed
First error: None
Error line: 0
Error column: 0
Root element: note
Elements: 4
Nesting depth: 2
Lines: 6

  1. One root element <note> holds 4 elements and 1 attributes.
  2. Every opening tag has a matching closing tag, nested 2 levels deep.

One root, three child elements and an escaped ampersand: four elements, two levels deep.

An unescaped ampersand

XML document
<p>Fish & chips</p>

Result Result: Not well-formed
First error: A bare & must be written as & or start a valid entity reference.
Error line: 1
Error column: 9
Root element: —
Elements: 0
Nesting depth: 0
Lines: 1

  1. Scanned tags, attributes, comments, CDATA and entity references against the XML 1.0 syntax rules.
  2. Stopped at line 1, column 9: A bare & must be written as & or start a valid entity reference.

A literal & must be written as &. The check points to column 9, where the bare ampersand sits.

How it is calculated

well-formed = one root element AND every start tag matched in order AND attributes quoted and unique AND every & starts a known entity

root element
the single top-level element that contains all others
entity
a reference such as &, <, © or one declared in the DOCTYPE
depth
the largest number of elements nested inside one another

The document is scanned from the start, keeping a stack of open elements. Each end tag must match the element on top of the stack, so overlapping tags fail at once. Comments, CDATA sections, processing instructions and a DOCTYPE are recognised and skipped. Text and attribute values are checked for a raw less-than sign and for ampersands that do not begin a predefined, numeric or declared entity. Positions count lines from 1 and columns from 1.

When not to use it

  • To confirm a document follows a specific XML Schema or DTD, use a schema-aware validator.
  • For HTML pages, which allow unclosed tags that XML forbids, use an HTML checker instead.

Common mistakes

  • Leaving an ampersand in a URL or company name unescaped instead of writing &.
  • Putting a blank line or comment before the XML declaration, which must come first.
  • Pasting two records one after another, which gives the file two root elements.

Frequently asked questions

What is the difference between well-formed and valid XML?

Well-formed means the document follows the XML syntax rules: matched tags, a single root, quoted attributes and escaped special characters. Valid means it also matches a DTD or XML Schema that fixes which elements and attributes are allowed. This check covers the first; any XML parser rejects a document that fails it.

Why does only the first error appear?

XML parsers are required to stop at the first fatal error, because everything after a broken tag is ambiguous. Fix the reported problem and the check moves on to the next one, if any.

Is the XML declaration required?

No. The XML declaration, which starts with a question-mark tag naming the version, is optional for XML 1.0 documents, but if it is present it must be the very first characters in the file, with nothing before it.

Are tag names case-sensitive?

Yes. An element opened as Item and closed as item uses two different names in XML, so that pair is reported as a mismatched end tag.

Does it handle entities defined in a DOCTYPE?

Entities declared with an ENTITY line in an internal DOCTYPE subset are accepted in text. External DTD files are not fetched, so entities defined only there are reported as undefined.

Can I check SVG or RSS files?

Yes. SVG, RSS, Atom, sitemaps and Office XML parts are all XML, so they follow the same well-formedness rules and can be pasted or opened as files.

Cite this tool

Using this tool in an assignment, article or report? Copy a citation, or a link for your website.

APA

Tools Directory Editorial Team. (2026, October 12). XML Validator. Tools Directory. Retrieved October 26, 2026, from https://tools.milunir.com/developer-tools/data-format-converters/xml-validator/

MLA

Tools Directory Editorial Team. “XML Validator.” Tools Directory, 12 Oct. 2026, https://tools.milunir.com/developer-tools/data-format-converters/xml-validator/. Accessed 26 Oct. 2026.

Chicago

Tools Directory Editorial Team. “XML Validator.” Tools Directory. Last modified October 12, 2026. Accessed October 26, 2026. https://tools.milunir.com/developer-tools/data-format-converters/xml-validator/.

Link<a href="https://tools.milunir.com/developer-tools/data-format-converters/xml-validator/">XML Validator – Tools Directory</a>