XML Validator — Validate XML Syntax & Well-Formedness
Understanding the Basics
XML (eXtensible Markup Language) is a markup language defined by the W3C that uses nested tags to represent hierarchical data. Unlike HTML (which browsers render leniently), XML parsers are strict: a document is either "well-formed" (following all XML syntax rules) or invalid, with no error recovery. Well-formedness rules include: every opening tag must have a matching closing tag, tags must be properly nested (never crossing), attribute values must be quoted, the document must have exactly one root element, and reserved characters like < and & must be escaped as < and &. Beyond well-formedness, an XML document can also be "valid" — conforming to a Document Type Definition (DTD) or XML Schema (XSD) that constrains what elements and attributes are allowed. XML remains the dominant format in enterprise systems: SOAP web services, JEE application descriptors, Maven POM files, Microsoft Office OpenXML, SVG graphics, RSS/Atom feeds, and Android layout files all use XML. Validating XML before processing prevents entire classes of downstream parse failures and integration errors. Our validator checks well-formedness using the @xmldom/xmldom library and reports precise line/column error locations.
How to Use the Tool
- Paste your XML document into the editor.
- The validator checks well-formedness automatically, highlighting any structural errors.
- Error messages include the line number and column position of the offending character or tag.
- Fix the reported issue and the validation status updates in real time.
- For DTD or XSD validation, use the "Schema Validation" mode and provide your schema document.
Key Features & Specifications
- Real-time well-formedness checking with line and column error positions
- Detects unclosed tags, mismatched nesting, unquoted attributes, and illegal characters
- Checks for exactly one root element (multiple root elements are invalid XML)
- Validates XML declarations (<?xml version="1.0" encoding="UTF-8"?>)
- Handles UTF-8, UTF-16, and ISO-8859-1 character encodings
Frequently Asked Questions (FAQ)
- Q:What is the difference between well-formed and valid XML?
- Well-formed XML follows the basic XML syntax rules (proper nesting, closed tags, quoted attributes). Valid XML additionally conforms to a schema (DTD or XSD) that defines which elements and attributes are allowed in which context. All valid XML is well-formed, but not all well-formed XML is valid.
- Q:Why does my XML work in the browser but fail validation?
- Web browsers parse HTML (which is lenient and error-recovering), not strict XML. Even XHTML served as text/html is parsed with HTML5 error correction rules. An XML parser applies zero error recovery — any syntax mistake is a fatal error.
- Q:How do I include a less-than sign (<) inside XML content?
- The < character must be escaped as the entity reference < inside XML text content and attribute values. Similarly, & must be &, > is recommended as >, " in attributes as ", and ' as '.