From: Grant M. <gr...@us...> - 2002-10-09 23:06:10
|
Update of /cvsroot/perl-xml/xml-filter-nsnormalise/lib/XML/Filter In directory usw-pr-cvs1:/tmp/cvs-serv17032/lib/XML/Filter Modified Files: NSNormalise.pm Log Message: - fixed fatal error on mapping to the same prefix the document already uses - added xmlnsnorm command-line utility - fixed typo in sample code Index: NSNormalise.pm =================================================================== RCS file: /cvsroot/perl-xml/xml-filter-nsnormalise/lib/XML/Filter/NSNormalise.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- NSNormalise.pm 9 Oct 2002 02:31:58 -0000 1.2 +++ NSNormalise.pm 9 Oct 2002 23:06:08 -0000 1.3 @@ -10,7 +10,7 @@ use vars qw($VERSION @ISA); -$VERSION = '0.01'; +$VERSION = '0.02'; @ISA = qw(XML::SAX::Base); @@ -96,8 +96,10 @@ if($attr->{Prefix} eq 'xmlns') { if($self->{ReverseMap}->{$attr->{LocalName}}) { - die "Cannot map '$self->{ReverseMap}->{$attr->{LocalName}}' to " . - "'$attr->{LocalName}' - prefix already occurs in document"; + if($attr->{Value} ne $self->{ReverseMap}->{$attr->{LocalName}}) { + die "Cannot map '$self->{ReverseMap}->{$attr->{LocalName}}' to " . + "'$attr->{LocalName}' - prefix already occurs in document"; + } } if($self->{Map}->{$attr->{Value}}) { $attr = { %$attr }; @@ -182,7 +184,7 @@ ... through this filter ... XML::Filter::NSNormalise->new( - Map => {=20 + Map => { 'http://purl.org/dc/elements/1.1/' => 'dc' } ) @@ -196,7 +198,15 @@ <dc:date>2002-10-08</dc:date> </rdf:RDF> -You can specify more than one namespace URI to prefix mapping. +You can specify more than one namespace URI to prefix mapping, eg: + + XML::Filter::NSNormalise->new( + Map => { + 'http://purl.org/dc/elements/1.1/' => 'dc', + 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' => 'rdf', + 'http://purl.org/rss/1.0/modules/syndication/' => 'syn' + } + ) =head1 METHODS @@ -214,10 +224,18 @@ =head1 ERROR HANDLING Attempting to map more than one URI to the same prefix will cause a fatal -exception. +exception, eg: + + XML::Filter::NSNormalise->new( + Map => { + 'http://x.com/ => 'z', + 'http://y.com/ => 'z' + } + ) Attempting to map a URI to a prefix that is already mapped to a different URI -will cause a fatal exception. +will cause a fatal exception (eg: you map a URI to the prefix 'foo' but the +document your are filtering already uses 'foo' for a different URI). =head1 SEE ALSO |