Skip to content

XML Validator & Checker

Find the line and column of XML syntax problems such as mismatched tags or unescaped ampersands.

Runs in your browser Free, no sign-up
Loading tool workspace...

What is XML Validator?

This XML validator checks whether an XML document is well-formed, the basic requirement every XML parser enforces. Well-formed XML has exactly one root element, every opening tag closed in the right order, quoted attribute values, no duplicate attributes, and special characters such as & and < escaped as &amp; and &lt;.

Paste your XML and the check runs as you type. A well-formed document gets a confirmation with its root element and element count; otherwise you see the parser's error with its line and column, such as a mismatched closing tag or an unescaped ampersand.

How to use XML Validator

  1. Paste your XML document or fragment into the input box.
  2. Read the result: "Well-formed XML" with the root element and element count means the document parses.
  3. If there is an error, go to the line and column in the message and fix the tag, attribute or character.
  4. Check again, then use the XML Formatter to indent the document.

Key features

  • Well-formedness check against the XML 1.0 rules
  • Error message with line and column
  • Root element and element count for valid documents
  • Checks as you type
  • Detects mismatched tags, unclosed elements and unescaped characters
  • Runs in your browser; documents are not uploaded

Common use cases

  • Checking SOAP requests and responses
  • Validating RSS and Atom feeds and XML sitemaps before publishing
  • Finding the broken tag in Maven pom.xml or Android layout files
  • Verifying XML exported from other systems before importing it
  • Checking SVG files that fail to render

Technical details & standards

The document is parsed with the browser's DOMParser as application/xml, which applies the well-formedness rules of the XML 1.0 specification. When the parser reports an error, it is shown as "Line N, column M: message" so you can go straight to the problem; browsers word the message slightly differently, but the position is the same.

This is a well-formedness check, not schema validation: it does not check the document against an XSD, DTD or RELAX NG schema, so a well-formed document can still have the wrong elements for its format. For schema validation, use xmllint --schema schema.xsd file.xml or your language's XML library.

Check XML syntax in code and on the command line

To check XML files in a build or CI job, use a parser that fails on malformed input. Each example below rejects the same broken document, <note><to>Alex</note>.

Terminal (xmllint)

xmllint --noout note.xml
# note.xml:1: parser error : Opening and ending tag mismatch: to line 1 and note

xmllint comes with libxml2 and is preinstalled on macOS and most Linux distributions. It prints nothing and exits with 0 when the file is well-formed.

Python

import xml.etree.ElementTree as ET

try:
    ET.fromstring("<note><to>Alex</note>")
except ET.ParseError as e:
    print("Invalid XML:", e)   # mismatched tag: line 1, column 16

JavaScript (browser)

const doc = new DOMParser().parseFromString("<note><to>Alex</note>", "application/xml");
const error = doc.querySelector("parsererror");
console.log(error ? error.textContent : "Well-formed");

DOMParser does not throw; it returns a document containing a parsererror element, which is what this validator reads.

Frequently asked questions

What does well-formed XML mean?

The document follows XML's basic syntax rules: one root element, every element properly opened and closed and correctly nested, quoted attribute values, unique attribute names, and & and < escaped. Every XML parser rejects documents that are not well-formed.

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

Well-formed means the syntax is correct. Valid means it is well-formed and also follows a schema (XSD or DTD) that defines which elements and attributes are allowed. This tool checks well-formedness.

How do I fix an error about an ampersand?

A bare & starts an entity reference, so it must be written as &amp; in text and attribute values. Likewise write < as &lt;. You can also wrap text containing many special characters in a <![CDATA[ … ]]> section.

Can an XML document have more than one root element?

No. A well-formed document has exactly one root element that contains everything else. If you have several top-level elements, wrap them in a single parent element.

How do I check if XML is valid online?

Paste the XML into the validator. If it is not well-formed, the first error is shown with its line and column number; fix it and check again.

Can it validate XML against an XSD schema?

No. It checks that the XML is well-formed: correct syntax, one root element and properly nested tags. It does not load an XSD, DTD or RELAX NG schema, so it cannot tell you whether the elements match one.

Is my data safe?

Processing happens locally in your browser. Tool input is not sent to CodeUnpack servers.

Does it work offline?

Once the page has loaded, this tool can process input without an internet connection.

More validators & checkers tools

View all