How to validate XML against a DTD
- Open the validator and paste, drop or fetch the XML document.
- Expand Validate against a schema. For a separate DTD file, add it on the Paste or Upload tab: it is applied as if the document declared it. For a DTD written inside the document, choose the DOCTYPE tab.
- Press Validate and click an error to jump to its line.
External DTD or DOCTYPE
A document can carry its DTD in the internal subset of its <!DOCTYPE>. The DOCTYPE tab validates against exactly that. A DOCTYPE that only points at an external file (SYSTEM "book.dtd") is not followed, since the validator never reaches the network or your disk on its own; upload that .dtd instead.
Modular DTDs that pull in parts through parameter entities (<!ENTITY % parts SYSTEM "parts.mod">) work when you choose all of the files together; the one nothing else refers to becomes the main file.
What a DTD checks
A DTD describes which elements may appear and in what order, which attributes they take with their types and defaults, ID and IDREF links, and entities. It does not know about namespaces or data types such as dates and decimals; for those, the same document needs an XSD or RelaxNG schema.
Validation runs on libxml2, so the result matches xmllint --dtdvalid and most server-side parsers.
Common DTD errors
- No declaration for element
- Element content does not follow the DTD
- No declaration for attribute
- Element does not carry attribute
- Entity not defined
In CI and from code
From the command line or GitHub Actions, or through the API with doctype=true for the document's own DTD:
npx @xmlvalid/cli validate "docs/**/*.xml" --schema-file book.dtd
From the catalog
Official schemas with all their files in place. Open one to see what it checks, or validate against it straight away.
- XHTML 1.0 Strict: The Strict document type of XHTML 1.0, for pages and content exports written as XML.
- XHTML 1.1: XHTML 1.1, the modular XHTML used by EPUB 2 books and some publishing pipelines.
- SVG 1.1: SVG images checked against the SVG 1.1 DTD: elements, attributes and nesting.
- MyBatis 3 mapper: MyBatis mapper XML files: SQL statements, result maps and dynamic SQL.
- MyBatis 3 configuration: The mybatis-config.xml file: settings, type aliases, environments and mappers.
- Hibernate configuration 3.0: The hibernate.cfg.xml file, still read by Hibernate up to version 6.
- Log4j 1.2 configuration: The log4j.xml configuration of Log4j 1.2 and of Reload4j, its maintained fork.
- Spring beans 2.0 DTD: Spring application contexts written against the beans DTD.
- Apple property list 1.0: XML property lists: Info.plist of apps, launchd jobs, configuration profiles.
- DocBook 4.5: DocBook documents written before version 5: no namespace, DTD instead of RelaxNG.
- DITA 1.3 topic: A generic DITA topic, the base of every DITA information type.
- DITA 1.3 concept: A DITA concept topic: background and explanation.
- DITA 1.3 task: A DITA task topic: step-by-step instructions.
- DITA 1.3 reference: A DITA reference topic: tables, properties and lookup information.
- DITA 1.3 map: A DITA map: the table of contents that orders topics into a publication.
- DITA 1.3 bookmap: A DITA bookmap: a map with book structure, front matter, chapters and appendices.
- JATS 1.3: Journal articles in JATS, the format PubMed Central, Crossref workflows and most scholarly publishers use.
- MathML 3: Mathematical formulas in MathML 3, presentation and content markup.
Questions
Is my XML uploaded?
No. The document and the DTD are validated on your machine with WebAssembly; only the API and URL monitors run on our servers.
Why is my external DTD not loaded?
The validator does not fetch files a document refers to, whether on the web or on your disk. Upload the .dtd with the document, or put the declarations in the DOCTYPE's internal subset.
Can it check data types?
No, a DTD has no data types beyond a few attribute types (ID, IDREF, NMTOKEN and so on). Use XSD or RelaxNG to check dates, numbers and patterns.
How large can the file be?
Up to 50 MB without an account and 1 GB with a free one, streamed in constant memory.
Other schema languages
- XSD validator (XML Schema)
- RelaxNG validator (RelaxNG)
- Schematron validator for e-invoices (Schematron)