NAME

XML::DTDParser - quick&dirty DTD parser

Version 1.1

SYNOPSIS

  use XML::DTDParser qw(ParseDTD);

  open DTD, "<$dtdfile" or die "Cannot open $dtdfile : $!\n";
  my $DTDtext;
  { local $/;
	$DTDtext = <DTD>
  }
  close DTD;
  $DTD = ParseDTD $DTDtext;

DESCRIPTION

This module parses a DTD 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 DTD 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 DTD specifies that a tag should contain either CHILD1 or CHILD2 you only get that CHILD1 and CHILD2 are optional. That is is the DTD contains <!ELEMENT FOO (BAR|BAZ)> the result will be the same is if it contained <!ELEMENT FOO (BAR?,BAZ?)>

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

EXPORT

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

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 ... SYSTEM "..."> declarations those are read and parsed as needed. The paths are relative to current directory.

The module currently doesn't support URLs here.

FindDTDRoot
$DTD = ParseDTD $DTDtext;
@roots = FindDTDRoot $DTD;

Returns all tags that have no parent. There could be several such tags defined by the DTD. Especialy if it used some common includes.

AUTHOR

Jenda@Krynicky.cz http://Jenda.Krynicky.cz

COPYRIGHT

Copyright (c) 2002 Jan Krynicky <Jenda@Krynicky.cz>. All rights reserved.

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