The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


XML::DTD::Parser - Perl module for parsing XML DTDs


  use XML::DTD::Parser;

  my $dp = new XML::DTD::Parser [ ($val) ];


  XML::DTD::Parser is a support module for top level parsing of an XML
  DTD. The following methods are provided.
 my $dp = new XML::DTD::Parser [ ($val) ];

Construct a new XML::DTD::Parser object.

The parser will be validating, and hence will make parameter and character entity substitutions, if the argument $val is present and non-zero.


if (XML::DTD::Parser->isa($obj) { ... }

Test object type

 my $rt = '';
 $dp->parse(*FH, $rt);

Parse a DTD file.

 my $dtduri = ''
 my $dtd = LWP::Simple::get($dtduri);
 $dp->parse(undef, $dtd, $dtduri);

Parse a DTD from a URL.

If the parser is validating, the URI of the document containing the DTD should be passed. If it isn't, it is arbitrarily given the relative URI unknown.dtd.

 my $dp = DML::DTD::Parser->new(1);
 my $file = 'file.dtd'
 my $rt = '';
 $dp->parse(*FH, $rt, $file);

For a correct validating parse of a file.

If the URI isn't absolute, then it is converted into an absolute file: URI relative to the current working directory. The test for this assumes that the URI scheme is more than one character long, so that a DOS drive number isn't used as a scheme.

Since the default URI is relative, any relative URIs in external entity declarations will be interpreted relative to a (probably non-existent) file in the parser's current working directory. In this case it's probably safest not to use relative URIs in the DTD being parsed.

The order of parsing of $rt and $file is such that the internal subset can be passed in $rt, and the external subset in $file, however, if any of the output methods of subclass DTD is called, the result will be the merger of the internal and external subsets.




Brendt Wohlberg <>


Copyright (C) 2004-2010 by Brendt Wohlberg

This library is available under the terms of the GNU General Public License (GPL), described in the GPL file included in this distribution.


Peter Lamb <> added fetching of external entities, improved entity substitution, and implemented more robust parsing of some classes of declaration.