SYNOPSIS

  use XML::DTDParser qw(ParseDTD ParseDTDFile);

  $DTD = ParseDTD $DTDtext;
 #or
  $DTD = ParseDTDFile( $dtdfile)

DESCRIPTION

This module parses a \s-1DTD\s0 file and creates a data structure containing info about all tags, their allowed parameters, children, parents, optionality etc. etc. etc.

Since I'm too lazy to document the structure, parse a \s-1DTD\s0 you need and print the result to a file using Data::Dumper. The datastructure should be selfevident.

Note: The module should be able to parse just about anything, but it intentionaly looses some information. Eg. if the \s-1DTD\s0 specifies that a tag should contain either \s-1CHILD1\s0 or \s-1CHILD2\s0 you only get that \s-1CHILD1\s0 and \s-1CHILD2\s0 are optional. That is is the \s-1DTD\s0 contains <!ELEMENT \s-1FOO\s0 (BAR|BAZ)> the result will be the same is if it contained <!ELEMENT \s-1FOO\s0 (\s-1BAR\s0?,BAZ?)>

You get the original unparsed parameter list as well so if you need this information you may parse it yourself.

Since version 1.6 this module supports my \*(L"extensions\*(R" to DTDs. If the \s-1DTD\s0 contains a comment in form

<!--#info element=XXX foo=bar greeting="Hello World!" person='d''Artagnan'-->

and there is an element \s-1XXX\s0 in the \s-1DTD\s0, the resulting hash for the \s-1XXX\s0 will contain

'foo' => 'bar', 'person' => 'd\'Artagnan', 'greeting => 'Hello World!'

If the \s-1DTD\s0 contains

<!--#info element=XXX attribute=YYY break=no-->

the

$DTD->{XXX}->{attributes}->{YYY}->[4]

will be set to

{ break => 'no' }

I use this parser to import the \s-1DTD\s0 into the database so that I could map some fields to certain tags for output and I want to be able to specify the mapping inside the file:

<!--#info element=TagName map_to="FieldName"-->

\s-1EXPORT\s0

By default the module exports all (both) it's functions. If you only want one, or none use

use XML::DTDParser qw(ParseDTD); or use XML::DTDParser qw();

ParseDTD

$DTD = ParseDTD $DTDtext; Parses the $DTDtext and creates a data structure. If the $DTDtext contains some <!ENTITY ... \s-1SYSTEM\s0 \*(L"...\*(R"> declarations those are read and parsed as needed. The paths are relative to current directory. The module currently doesn't support URLs here yet.

ParseDTDFile

$DTD = ParseDTDFile $DTDfile; Parses the contents of $DTDfile and creates a data structure. If the $DTDfile contains some <!ENTITY ... \s-1SYSTEM\s0 \*(L"...\*(R"> declarations those are read and parsed as needed. The paths are relative to the $DTDfile. The module currently doesn't support URLs here yet.

FindDTDRoot

$DTD = ParseDTD $DTDtext; @roots = FindDTDRoot $DTD; Returns all tags that have no parent. There could be several such tags defined by the \s-1DTD\s0. Especialy if it used some common includes.

AUTHOR

[email protected] http://Jenda.Krynicky.cz

COPYRIGHT

Copyright (c) 2002 Jan Krynicky <[email protected]>. All rights reserved.

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