XML Validator
Well-formed XML requires: a single root element, all tags closed and properly nested, case-sensitive tag names, attribute values in double or single quotes, and five special characters escaped (< > & " '). The XML declaration (<?xml version="1.0" encoding="UTF-8"?>) specifies version and encoding. Namespaces (xmlns) prevent naming conflicts when combining XML from multiple vocabularies.
Validate XML syntax and structure online. Detects parse errors, counts elements, attributes, text nodes, and comments. Shows document statistics, namespace detection, max nesting depth, and formatted output.
Presets
XML Input
XML Reference
| Rule | Valid | Invalid |
|---|---|---|
| Tags must be closed | <item>text</item> | <item>text |
| Tags are case-sensitive | <Item></Item> | <Item></item> |
| Proper nesting | <a><b></b></a> | <a><b></a></b> |
| Single root element | <root>...</root> | <a/><b/> |
| Attribute values quoted | <x a="1"/> | <x a=1/> |
| Special chars escaped | < & > | < & > |
How to Use
- 1
Paste XML
Paste your XML document in the input area. Or click a preset to load example XML (valid document, namespaces, invalid XML, SVG).
- 2
View validation result
The validator immediately shows whether your XML is well-formed. If invalid, specific parse error messages are displayed.
- 3
Review document statistics
For valid XML, see element count, attribute count, text nodes, comments, max nesting depth, document size, and detected namespaces.
- 4
Format and copy
Click Show Formatted XML to pretty-print the document with proper indentation. Click Copy to copy the formatted output.
Frequently Asked Questions
- What is well-formed XML?
- Well-formed XML follows syntax rules: a single root element, all tags properly closed and nested, attribute values in quotes, case-sensitive tag names, and special characters escaped (< > & " '). Well-formed XML can be parsed by any XML parser. The XML declaration (<?xml version="1.0"?>) is recommended but optional.
- What is the difference between well-formed and valid XML?
- Well-formed XML follows XML syntax rules. Valid XML is well-formed AND conforms to a schema (DTD, XSD, or Relax NG) that defines allowed elements, attributes, and structure. A document can be well-formed but not valid (correct syntax, wrong structure). This tool checks well-formedness.
- What are XML namespaces?
- XML namespaces prevent naming conflicts when combining XML from different sources. Declared with xmlns:prefix="URI" (e.g., xmlns:atom="http://www.w3.org/2005/Atom"). The URI is an identifier, not necessarily a real URL. Default namespace (xmlns="...") applies to the element and descendants without a prefix.
- What characters must be escaped in XML?
- Five characters must be escaped in XML text content: < as <, > as >, & as &, " as " (in attributes), and ' as ' (in attributes). Alternatively, use CDATA sections (<![CDATA[...]]>) for blocks of text containing many special characters.
- How is XML different from HTML?
- XML requires strict syntax: all tags must be closed (<br/> not <br>), tags are case-sensitive (<Item> differs from <item>), attributes must be quoted, and there must be exactly one root element. HTML is more lenient — browsers tolerate unclosed tags, unquoted attributes, and mixed case. XHTML is HTML that follows XML rules.
- What is the XML declaration?
- The XML declaration (<?xml version="1.0" encoding="UTF-8"?>) appears at the very beginning of an XML document. It specifies the XML version (1.0 or 1.1), character encoding (UTF-8, UTF-16, ISO-8859-1), and optionally standalone="yes|no". It is recommended but not required for well-formed XML.