#!/usr/local/bin/perl use Getopt::Std; getopts ('hv', \%opts); $me = `basename $0`; chop $me; $usage = "$me [-hv] [file ... fileN] This program lists all the element and attribute names used in the XML input file(s). Options: -h displays this help screen -v displays attribute values Known bugs: attribute values enclosed in single quotes are not handled properly "; die "$usage\n" if ($opts{h}); die "$usage\n" if (! @ARGV); $/ = "<"; while (<>) { s/\/>/ \/>/; if (/^[^\/]*\/?>/) { ($element, $content) = split(/>/,$_,2); ($element, $attributes) = split(/\s+/,$element,2); $attributes =~ s/\s*\/$//; $attributes =~ s/([^=]+)=([\"\'][^\"\']*[\"\'])/PRATTSEP$1=$2/g; $attributes =~ s/"\s+/"/g; $attributes =~ s/\s+"/"/g; $attributes =~ s/'\s+/'/g; $attributes =~ s/\s+'/'/g; $attributes =~ s/^PRATTSEP//; $attributes =~ s/PRATTSEP /PRATTSEP/g; unless ($opts{v}) { # The following attributes are not displayed unless the -v option is supplied $attributes =~ s/orig="[^"]*"//; $attributes =~ s/reg="[^"]*"//; $attributes =~ s/PRATTSEPid="[^"]*"//; $attributes =~ s/^id="[^"]*"//; $attributes =~ s/entity="[^"]*"//; $attributes =~ s/sic="[^"]*"//; $attributes =~ s/corr="[^"]*"//; $attributes =~ s/entityref="[^"]*"//; $attributes =~ s/target="[^"]*"//; $attributes =~ s/PRATTSEPn="[^"]*"//; $attributes =~ s/^n="[^"]*"//; $attributes =~ s/PRATTSEPpid="[^"]*"//; $attributes =~ s/^pid="[^"]*"//; } $attributes =~ s/^PRATTSEP//; $attributes =~ s/\n/ /g; unless (($element =~ /ENTITY/)||($element =~ /NOTATION/)|| ($element =~ /ATTLIST/)||($element =~ /\?xml/)||($element =~ /!--/)) { @elist{$element} = $element; @alist = split(/PRATTSEP/, $attributes); foreach $i (0..$#alist) { ($attname, $attvalue) = split(/=/, $alist[$i]); $attname =~ s/^\s*//; $attname =~ s/\s*$//; $attvalue =~ s/\n//g; $attvalue =~ s/^"//; $attvalue =~ s/"$//; $attvalue =~ s/^\s*//; $attvalue =~ s/\s*$//; $attvalue =~ s/\[/\\\[/g; $attvalue =~ s/\(/\\\(/g; $attvalue =~ s/\)/\\\)/g; $alistkey = $element."PRELATSEP".$attname; unless (@alist{$alistkey} =~ / $attvalue /) { @alist{$alistkey} = @alist{$alistkey}." ".$attvalue." "; } } } } } foreach $key (sort(keys(%elist))) { print "$elist{$key}\n"; foreach $item (sort(keys(%alist))) { if ($item =~ /^$elist{$key}PRELATSEP/) { $label = $item; $label =~ s/^$elist{$key}PRELATSEP//; $value = $alist{$item}; $value =~ s/ /, /g; $value =~ s/^ //; print " $label=$value\n"; } } }