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);
$newobj->setOwnerDocument($node->getOwnerDocument);
}
$node->appendChild($newobj);
+
+ process($newobj, {}, $clean, $nsup);
} 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);
+ }
+ }
+ }
+
my (undef, undef, $tag) = $nsup->process_element_name($child->getTagName);
my $id;
# check all substitutions to see if we found anything
# appropriate
for my $key (keys %$obj) {
- if (($key =~ /^\Q$tag\E\.(.*)$/) ||
- (defined($id) && $key =~ /^#\Q$id\E\.(.*)$/)) {
+ if (($key =~ /^\Q$tag\E\/(.*)$/) ||
+ (defined($id) && $key =~ /^#\Q$id\E\/(.*)$/)) {
$child->setAttribute($1, $obj->{$key});
}
}
process($child, $obj, $clean, $nsup) unless ($processed);
+ $nsup->pop_context;
}
} elsif (ref($obj) eq 'ARRAY') { # repeat
my $doc = $node->getOwnerDocument;
}
for my $instance (@$obj) {
+ next if (!defined($instance));
my $newnode = $frag->cloneNode(1);
process($newnode, $instance, $clean, $nsup);
}
$frag->dispose;
- $nsup->pop_context;
- return;
}
clean($node, $nsup) if $clean;
- $nsup->pop_context;
}
sub clean {
my $num = scalar @elems;
for my $ref (@$array) {
- $ref->{$tag} = $elems[$i++ % $num];
+ if (defined($ref)) {
+ $ref->{$tag} = $elems[$i++ % $num];
+ }
}
return $array;