#!/usr/bin/perl

use XML::Parser::Expat;

$parser = new XML::Parser::Expat(ParseParamEnt=>1);
$parser->setHandlers('Element' => \&eh, 'ExternEnt' => \&enth);

open(FOO, $ARGV[0]) or die "Couldn't open";
$parser->parse(*FOO);
close(FOO);

sub eh
{
	my ($p, $name, $model)=@_;
	$model =~ s/#PCDATA\|?//;
	$model =~ s/^\((.*)\)$/\1/;
	if ($model eq "EMPTY" or $model eq "") {
		print "P_", $name, "\t-> $name\n";
	} else {
		$model =~ s/(\w[\w\d]+)\+/(\1,\1*)/g;
		$model =~ s/(\w[\w\d]+)/P_\1/g;
		print "P_", $name, "\t-> $name ", $model, "\n";
	}
	#print $name, " ", $model, "\n";
}

sub enth
{
	my($p, $base, $sysid, $pubid)=@_;
	#print "$sysid\n";
	open(ENT, "<$sysid") || die "cannot open $sysid";
	my $e=join('', <ENT>);
	close(ENT);
	return $e;
}
