Skip to content

Commit

Permalink
Fix replace logic if element to replace is root
Browse files Browse the repository at this point in the history
  • Loading branch information
tomill committed Feb 13, 2010
1 parent d2c6633 commit f0f9750
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/Template/Semantic/Document.pm
Expand Up @@ -146,7 +146,12 @@ sub _assign_value {

my $parted = $self->_to_node($node->serialize);
$self->_query($parted, $value);
$node->replaceNode($parted);

if ($node->isSameNode( $self->{dom}->documentElement )) { # to replace root
$self->{dom}->setDocumentElement($parted);
} else {
$node->replaceNode($parted);
}
}
}

Expand Down Expand Up @@ -374,7 +379,7 @@ Gets the result as L<XML::LibXML::Document>.
=head1 SEE ALSO
L<Template::Semantic>
L<Template::Semantic>, L<XML::LibXML::Document>
=head1 AUTHOR
Expand Down
12 changes: 12 additions & 0 deletions t/05_value-type.t
Expand Up @@ -225,6 +225,18 @@ use XML::LibXML;
<a href="zzz" class="yyy">xxx</a>
</root>
=== elem (root) x hashref
--- note: test for "replaceChild: HIERARCHY_REQUEST_ERR"
--- vars
'/root' => {
'.' => 'xxx',
'./@class' => 'yyy',
}
--- template
<root class="foo"></root>
--- expected
<root class="yyy">xxx</root>
=== elem x list (xpath)
--- vars
'ul.list li' => [
Expand Down

0 comments on commit f0f9750

Please sign in to comment.