All you have to do is use a parser that has DTD validation enabled: option, which loads the DTD and weaves attribute default values into the document.Again, no validation is performed unless explicitly requested.XML schema is supported in a similar way, but requires an explicit schema to be provided: As described above, the parser support for DTDs depends on internal or external subsets of the XML file.

It will only contain log entries that appeared during the validation.

Similar to XSLT, there's also a less efficient but easier shortcut method to do one-shot Relax NG validation: lxml.etree also has XML Schema (XSD) support, using the class lxml.etree. The API is very similar to the Relax NG and DTD classes.

Pass an Element Tree object to construct a XMLSchema validator: From version 2.3 on lxml features ISO-Schematron support built on the de-facto reference implementation of Schematron, the pure-XSLT-1.0 skeleton implementation.

If you want to validate an XML document against a DTD that is not referenced by the document itself, you can use the keyword argument to parse from a file.

This also enables correct handling of include files from within the Relax NG parser.

You can then validate some Element Tree document against the schema.You'll get back True if the document is valid against the Relax NG schema, and False if not: Note that this error log is local to the Relax NG object.Apart from the built-in DTD support in parsers, lxml currently supports three schema languages: DTD, Relax NG and XML Schema.All three provide identical APIs in lxml, represented by validator classes with the obvious names.lxml also provides support for ISO-Schematron, based on the pure-XSLT skeleton implementation of Schematron: There is also basic support for The parser in lxml can do on-the-fly validation of a document against a DTD or an XML schema.The DTD is retrieved automatically based on the DOCTYPE of the parsed document.