From ce85fc0093e4b982ced20edbdbd26e1f2e195cce Mon Sep 17 00:00:00 2001 From: "sgunderson@bigfoot.com" <> Date: Sat, 12 Aug 2006 21:25:23 +0200 Subject: [PATCH] Fix the namespace handling in the Perl variant. --- perl/XML/Template.pm | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/perl/XML/Template.pm b/perl/XML/Template.pm index c148ecc..ed44d63 100644 --- a/perl/XML/Template.pm +++ b/perl/XML/Template.pm @@ -23,21 +23,7 @@ sub process { if (!defined($nsup)) { $nsup = XML::NamespaceSupport->new; } - $nsup->push_context; - - # see if this node contains any namespace declarations that are relevant - # for us - my $attrs = $node->getAttributes; - if (defined($attrs)) { - for my $attr ($attrs->getValues) { - my $name = $attr->getName; - if ($name =~ /^xmlns:(.*)$/) { - $nsup->declare_prefix($1, $attr->getValue); - $node->removeAttribute($name) if ($clean); - } - } - } - + if (!ref($obj)) { # overwrite for my $child ($node->getChildNodes) { $node->removeChild($child); @@ -62,8 +48,23 @@ sub process { } elsif (ref($obj) eq 'HASH') { # substitute for my $child ($node->getChildNodes) { my $processed = 0; + $nsup->push_context; if ($child->getNodeType == XML::DOM::ELEMENT_NODE) { + # see if this node contains any namespace declarations that are relevant + # for us + my $attrs = $child->getAttributes; + if (defined($attrs)) { + for my $attr ($attrs->getValues) { + my $name = $attr->getName; + if ($name =~ /^xmlns:(.*)$/) { + $nsup->declare_prefix($1, $attr->getValue); + $child->removeAttribute($name) if ($clean); + } + } + } + print $child->getTagName, "\n"; + my (undef, undef, $tag) = $nsup->process_element_name($child->getTagName); my $id; @@ -97,6 +98,7 @@ sub process { } process($child, $obj, $clean, $nsup) unless ($processed); + $nsup->pop_context; } } elsif (ref($obj) eq 'ARRAY') { # repeat my $doc = $node->getOwnerDocument; @@ -118,12 +120,10 @@ sub process { } $frag->dispose; - $nsup->pop_context; return; } clean($node, $nsup) if $clean; - $nsup->pop_context; } sub clean { -- 2.39.2