The manakai project


An XML DTD validator


  use Web::XML::DTDValidator;
  $validator = Web::XML::DTDValidator->new;
  $validator->onerror (sub {
    my %error = @_;
  $validator->validate_document ($doc);


The Web::XML::DTDValidator module is an XML DTD validator, which can be used in combination with Web::XML::Parser.

This module implements validation of DOM Document against its DTD. For example, it checks whether elements in the document conform to the content models in the DTD, and whether the attribute values in the document conform to the attribute definitions in the DTD. It can't check syntactical or physical constraints of XML (e.g. how XML entities are used in the document) as the Document does not preserve physical structures of the document.

To validate an XML document, including both physical and logical constraints, streaming API of the parser module Web::XML::Parser, the strict-checker module Web::XML::Parser::XML1Checker for the parser, and an entity resolution implementation onextentref handler for the parser, must be used to create a Document input to this module.

This module is also invoked as part of Web::HTML::Validator validation process.


Following methods are available:

$validator = Web::XML::DTDValidator->new

Create a new validator.

$code = $validator->onerror
$validator->onerror ($new_code)

Get or set the error handler for the validator. Any parse error, as well as warning and additional processing information, is reported to the handler. See <> for details of error handling.

The code is not expected to throw any exception.

The value should not be set while the validator is running. If the value is changed, the result is undefined.

$validator->validate_document ($doc)

Validate the document.

The input must be a DOM Document object. See <> for the requirements on the Document object.

Any validity or other error is reported through the onerror handler. If no error with level m has been reported, the document has no violation to the validity constraints supported by this module. (However, not all errors with level m are violation to the validity constraints. There are other kinds of errors specified in relevant specifications.)



Extensible Markup Language (XML) 1.0 (Fifth Edition) <>.


Namespaces in XML 1.0 (Third Edition) <>.


XML processing and DOM Document Type Definitions <>.

XML 1.1 is not supported.

Unless otherwise specified, a document MUST NOT be in error.

A conformance checker MUST validate an XML document against its DTD when the document contains the DOCTYPE declaration. Otherwise, it MAY validate the document (but a document without the DOCTYPE declaration is always invalid by definition).


Web::XML::Parser, Web::XML::Parser::XML1Checker.



Wakaba <>.


Copyright 2003-2015 Wakaba <>

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.