use strict; use warnings; use XML::LibXML qw( ); sub format_uri { my ($uri) = @_; return '' if !defined($uri); $uri =~ s/\}/%7D/g; return "{$uri}"; } ( my ($xml_file) = @ARGV ) == 1 or die("usage\n"); my $parser = XML::LibXML->new(); my $doc = $parser->parse_file($xml_file); my $root = $doc->documentElement(); my %seen; print "$_\n" for sort grep !$seen{$_}++, map { format_uri( $_->namespaceURI() ) . $_->localname() } $root->findnodes('//*');
Update: Now handles the null namespace.
|
|---|