formatter.input (XML)
Loading Editor...
formatter.output (XML)
Loading Editor...

XML Validator — Check XML Well-Formedness & Catch Errors Instantly

XML has been powering enterprise systems, document formats, and web services for over two decades. In that time, developers have collectively spent an uncountable number of hours staring at errors like this:

XML parsing error: mismatched tag at line 47, column 12

Or worse — no error at all, because the downstream system silently accepted malformed XML and processed it incorrectly for weeks before anyone noticed.

Our XML Validator gives you something better: paste your XML and get an immediate, precise diagnosis. Not just "your XML is invalid" — but exactly which tag is unclosed, which attribute is unquoted, which character needs escaping, and on which line. Fix it in seconds, not hours.

Two Levels of XML Validity — and Why Both Matter

XML has a two-tier validity model that confuses a surprising number of developers. Understanding it changes how you think about XML validation entirely.

1. Well-Formed XML (The Baseline)

A well-formed XML document follows the syntactic rules of the XML specification: every opening tag has a matching closing tag, tags are properly nested, attributes are quoted, there is exactly one root element, and special characters are correctly escaped. Any XML parser will reject a document that isn't well-formed — it won't even attempt to read the content.

2. Valid XML (The Stricter Standard)

A valid XML document is well-formed AND conforms to a schema — either a DTD (Document Type Definition) or an XSD (XML Schema Definition) — that specifies exactly which elements and attributes are allowed, in what order, with what data types. An XML document can be perfectly well-formed but still invalid against a schema if it contains unexpected elements, missing required attributes, or values of the wrong type.

What this tool validates: Our validator checks for well-formedness against the W3C XML 1.0 specification. If your XML isn't well-formed, nothing else matters — fix that first. For full schema validation against an XSD, you need a schema-aware validator, which is typically done server-side in tools like xmllint, Saxon, or within your IDE.

Most developers dealing with XML errors are dealing with well-formedness problems — the kind this tool catches completely. Schema violations are rarer and usually discovered during integration testing.

What Our XML Validator Checks

Every XML document submitted to our validator is checked against the following rules — in the order a real XML parser would encounter them:

XML Declaration

If present, the XML declaration (<?xml version="1.0" encoding="UTF-8"?>) must be the very first content in the document — before any whitespace, before any elements, before anything. Even a single space before the declaration breaks it.

Single Root Element

Every well-formed XML document must have exactly one root element that wraps all other elements. Multiple top-level elements, or no elements at all, are both invalid.

Invalid: two root elements
<!-- Invalid -->
<user>Alice</user>
<user>Bob</user>
Valid: single root element
<!-- Valid -->
<users>
  <user>Alice</user>
  <user>Bob</user>
</users>

Tag Matching and Nesting

Every opening tag must have a corresponding closing tag. Tags must be properly nested — a tag opened inside another tag must be closed before the parent tag closes.

Invalid: overlapping tags
<b><i>bold italic</b></i>
Valid: proper nesting
<b><i>bold italic</i></b>

Case Sensitivity

XML tag names are case-sensitive. <User> and <user> are completely different elements. An opening <User> tag must be closed with </User>, not </user>.

Attribute Quoting

All attribute values must be enclosed in quotes.

Invalid
<book category=fiction>
Valid
<book category="fiction">

Special Character Escaping

Five characters have special meaning in XML and must be escaped when used in element content or attribute values:

CharacterEscapeUsed In
<&lt;Element content, attributes
>&gt;Element content
&&amp;Element content, attributes
"&quot;Attribute values
'&apos;Attribute values

The most common offender is & — every unescaped & is a parsing error.

Empty Elements

Empty elements can be written as either a matched pair (<br></br>) or as a self-closing tag (<br/>). Both are valid.

Processing Instructions and Comments

Processing instructions (<?target data?>) and comments (<!-- comment -->) must be correctly formed. Comments cannot contain double dashes (--) within their content, and cannot end with --->.

The Most Destructive XML Errors in Production Systems

Not all XML errors are equal. Some break parsers immediately. Others slip through and cause downstream damage.

Unescaped Ampersands in Data Content

This is the single most common XML error in production systems. Company names ("Johnson & Johnson"), URLs with query parameters, and SQL queries embedded in XML all contain raw ampersands that break parsers.

<!-- Breaks the parser --> <company>AT&T</company> <url>https://example.com?id=1&page=2</url> <!-- Correct --> <company>AT&amp;T</company> <url>https://example.com?id=1&amp;page=2</url>

Namespace Declaration Errors

A missing namespace declaration causes namespace-aware parsers to reject the document even though the syntax looks fine.

<!-- Fails in namespace-aware parsers: undeclared prefix --> <soap:Envelope> <soap:Body>...</soap:Body> </soap:Envelope> <!-- Correct: namespace declared --> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body>...</soap:Body> </soap:Envelope>

Encoding Mismatches

If an XML document declares encoding="UTF-8" but the actual bytes are in ISO-8859-1 (Latin-1), parsers will reject it. This is common with XML generated by legacy systems or copied from Windows applications.

CDATA Section Misuse

CDATA sections (<![CDATA[ ... ]]>) allow you to include content without escaping. But they cannot contain the string ]]> within their content (since that's the closing delimiter).

Byte Order Mark (BOM) Issues

Some text editors save files with a UTF-8 Byte Order Mark (BOM) — three hidden bytes at the start of the file. Many XML parsers reject documents with a BOM because it appears before the XML declaration.

XML Validation by Industry — Where It Matters Most

Financial Services & Banking

Payment processing systems, SWIFT messaging, and FIX protocol implementations all rely on XML. A malformed SWIFT message can fail to process a payment.

Healthcare (HL7 & FHIR)

Patient records, lab results, and prescriptions transmitted as malformed XML can fail to process or be misattributed to the wrong patient.

E-Commerce & Retail (EDI)

EDI relies on XML for purchase orders and invoices. A malformed document can delay fulfillment and trigger supplier issues.

Government & Legal

Court filings and tax submissions are often XML. Malformed submissions are typically rejected automatically, requiring resubmission.

Software Development

Maven POM files, Spring configuration, and Android manifests are XML. A malformed file breaks the build for the entire team.

XML Validation Tools Across Your Development Stack

Our online validator is ideal for quick, ad-hoc validation. For systematic validation, here's how to integrate it:

Command Line — xmllint

# Check well-formedness xmllint --noout document.xml # Validate against XSD schema xmllint --noout --schema schema.xsd document.xml # Validate against DTD xmllint --noout --valid document.xml

Java — JAXP

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(xmlFile); // throws SAXException if invalid

Python — lxml

from lxml import etree # Well-formedness check tree = etree.parse("document.xml") # raises XMLSyntaxError if malformed # Schema validation schema = etree.XMLSchema(etree.parse("schema.xsd")) schema.validate(tree) print(schema.error_log) # validation errors

.NET — XmlDocument / XmlReader

XmlReaderSettings settings = new XmlReaderSettings(); settings.ValidationType = ValidationType.Schema; settings.Schemas.Add(null, "schema.xsd"); XmlReader reader = XmlReader.Create("document.xml", settings);

CI/CD Integration

# Validate all XML files in the repository find . -name "*.xml" -exec xmllint --noout {} \; 2>&1

Frequently Asked Questions

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

Well-formed XML follows basic syntax rules (proper tag nesting, quoted attributes, etc.). Valid XML is well-formed AND conforms to a specific schema (DTD or XSD) that defines which elements are permitted. Our validator checks well-formedness.

Why does my XML work in one system but fail in another?

Different parsers have different strictness. Some are lenient, others strict. The W3C spec requires strict parsing. If it fails here but works elsewhere, usage of a lenient parser is masking errors.

What does "entity reference" mean in an XML error?

It usually means you have an unescaped & inside your content that the parser thinks is starting a special code. Replace bare & with &amp;.

Can I validate XML with namespaces?

Yes. The validator handles XML with namespace declarations (xmlns) correctly and checks that prefixes are declared.

What is a CDATA section and when should I use it?

CDATA sections (<![CDATA[ ... ]]>) mark text to be ignored by the parser. Use them for embedding HTML, SQL, or code snippets with many special characters.

Why does my XML fail with a BOM error?

A Byte Order Mark (BOM) is a hidden character sequence some editors add to UTF-8 files. Parsers fail if it's before the XML declaration. Save as 'UTF-8 without BOM'.

What encoding should I use for XML?

UTF-8 is best and the default. Declare it: <?xml version="1.0" encoding="UTF-8"?>. Avoid legacy encodings like Windows-1252 unless absolutely necessary.

Can I validate SOAP messages with this tool?

Yes. SOAP messages are XML. Paste the whole envelope to check well-formedness. Schema validation is a separate step.

Does this tool validate against DTD or XSD schemas?

Not currently — it checks well-formedness. Full schema validation requires a schema-aware tool like xmllint or Java JAXP.

Is there a size limit for XML documents I can validate?

There is no hard limit. All processing happens in your browser. For very large files, use the file upload option.

Related Free Developer Tools

Stop Guessing. Start Validating.

Paste your XML above — malformed, minified, or fresh from a legacy system that hasn't been touched in years — and know in seconds exactly what's wrong and where to fix it.