in reply to LibXML - Removing Namespace?
Misery loves company. Found this snippet in LJ::Feed. (edit, fixed link)
# Strip namespace from child tags. Set default namespace, let # child tags inherit from it. So ghetto that we even have to do t +his # and LibXML can't on its own. my $normalize_ns = sub { my $str = shift; $str =~ s/(<\w+)\s+xmlns="\Q$ns\E"/$1/og; $str =~ s/<feed\b/<feed xmlns="$ns"/; $str =~ s/<entry>/<entry xmlns="$ns">/ if $opts->{'single_entr +y'}; return $str; };
I've resorted to what derby suggests for namespaced XHTML too and it works fine (this snippet is old and un-re-tested).
my $root = $doc->documentElement; my $xpc = XML::LibXML::XPathContext->new($html); $xpc->registerNs('x', 'http://www.w3.org/1999/xhtml'); my $htmls = $xpc->find('/x:html', $doc);
|
|---|