Posted on 2006-07-19 13:10:12-07 by karl
Make namespace recognition case-insensitive?

I'm trying to use this to parse some Podcast feeds, but found that the "itunes" qname is recognized by this this module if the namespace is exactly "http://www.itunes.com/DTDs/Podcast-1.0.dtd". But many feeds I find have the namespace as "http://www.itunes.com/dtds/podcast-1.0.dtd". The module is case-sensitive to this, so it does not pick up the "itunes" qname for those attributes, making it difficult for my XML::RAI extensions to find iTunes attributes.

It looks like the iTunes spec even uses the all-lowercase namespace, so I'm not sure why Parser.pm defines it this way.

But anyway, I was able to patch up Parser.pm to be case-insensitive when trying to match up qnames to namespaces with the following modifications. Perhaps others might find this useful.

Around line 52, before "my %xpath_ns = reverse %xpath_prefix;", insert

# Make xpath_ns URIs all lowercase to make ns case-insensitive foreach (keys %xpath_prefix) { $xpath_prefix{$_}=lc($xpath_prefix{$_})}

Around line 69, in "sub register_ns_prefix", after "my ($this, $prefix, $ns) = @_;", insert

# Make ns URIs all lowercase to make ns case-insensitive $ns = lc($ns);

And finally, around line 93, change "sub prefix { $xpath_ns{$_[1]} }" to:

sub prefix { $xpath_ns{lc($_[1])} } # Make ns URI all lowercase to make ns case-insensitive

--Karl.

Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.