SGML::DTD

Andrew McFarland andrew at mcfarland.co.uk
Mon Nov 19 17:51:46 CST 2001


I'm using perlSGML to parse DTDs. [1]

I'm having a couple of problems.

When I run this script it prints out a list of all the elements defined in 
strict.dtd, which is a copy of the XHTML 1.0 strict DTD (but using the HTML 
4.0 Loose DTD causes the same problem).

#! /usr/bin/perl

use SGML::DTD;
open(FHANDLE, 'strict.dtd');
$dtd = new SGML::DTD;
$dtd->read_dtd(\*FHANDLE);
@elements = $dtd->get_elements(0);
foreach (@elements) {print "$_\n"};

However, it gives the warnings:

SGML::EntMan:Unable to open "-//W3C//ENTITIES Latin1//EN//HTML" => ""
SGML::EntMan:Unable to open "-//W3C//ENTITIES Symbols//EN//HTML" => ""
SGML::EntMan:Unable to open "-//W3C//ENTITIES Special//EN//HTML" => ""

Are these serious problems, and how do I fix them?

The second problem is rather more serious.

I want this script to print a list of all the attributes of the STYLE element:

#! /usr/bin/perl
use strict;
use warnings;
use SGML::DTD;

open(DTD, 'strict.dtd');
my $dtd = new SGML::DTD;
$dtd->read_dtd(\*DTD);

my $elem = "style";

# %attributes has attribute names as keys
# and an array of attribute values as values.

my %attributes = $dtd->get_elem_attr($elem);

foreach (keys(%attributes)) {
         print "$_,";
         foreach ($attributes{$_}) {print "$_"};
         print "\n";
         };

It actually prints

dir,ARRAY(0x8286e40)
xml:space,ARRAY(0x82875e4)
title,ARRAY(0x82875b4)
lang,ARRAY(0x8286d80)
xml:lang,ARRAY(0x8286e10)
media,ARRAY(0x8286eac)
type,ARRAY(0x8286e88)

What should I do to fix this? I've tried various combinations of things, 
and I either get ARRAY(0x8286e40) or an empty string. It's too late to do 
any more at the moment :)

Andrew

[1] The ultimate plan is to use it in conjunction with Template Toolkit to 
produce reference material on the tags and attributes in the various 
flavors of (X)HTML I use. dtd2html isn't _quite_ what I need.

-- 
AA McFarland http://www.mcfarland.co.uk/andrew/
The LORD is my shepherd, I shall not be in want
Psalm 23:1 




More information about the Belfast-pm mailing list