I'm seeing some odd behavior with XML::LibXML.
The code below is intended to add <year>2005</year> to both <book> nodes. Is something wrong here? I've tried changing the XPath query (//library/book ) but the result is the same.
use strict;
use warnings;
use XML::LibXML;
my $xml = XML::LibXML->new->parse_string( << 'MAIN' );
  <library>
    <book>
      <title>Perl Best Practices</title>
      <author>Damian Conway</author>
      <isbn>0596001738</isbn>
      <pages>542</pages>
      <image src="http://www.oreilly.com/catalog/covers/perlbp.s.gif"
             width="145" height="190" />
    </book>
    <book>
      <title>Perl Cookbook, Second Edition</title>
      <author>Tom Christiansen</author>
      <author>Nathan Torkington</author>
      <isbn>0596003137</isbn>
      <pages>964</pages>
      <image src="http://www.oreilly.com/catalog/covers/perlckbk2.s.gif"
             width="145" height="190" />
    </book>
  </library>
MAIN
my ( $age ) = XML::LibXML->new
                ->parse_string( '<year>2005</year>' )
                  ->findnodes( './year' );
my @books = $xml->findnodes( '//book' );
$_->addChild( $age ) for @books;
print $xml->toString;
Output
<?xml version="1.0"?>
<library>
    <book>
      <title>Perl Best Practices</title>
      <author>Damian Conway</author>
      <isbn>0596001738</isbn>
      <pages>542</pages>
      <image src="http://www.oreilly.com/catalog/covers/perlbp.s.gif" width="145" height="190"/>
    </book>
    <book>
      <title>Perl Cookbook, Second Edition</title>
      <author>Tom Christiansen</author>
      <author>Nathan Torkington</author>
      <isbn>0596003137</isbn>
      <pages>964</pages>
      <image src="http://www.oreilly.com/catalog/covers/perlckbk2.s.gif" width="145" height="190"/>
    <year>2005</year></book>
  </library>
 
     
    