The name of the node is NodeX
, not Nodex
. That is all that is wrong with your code (except that, from your comments, it seems you may not be writing the altered XML back to the file) but this shows a more concise method that you may prefer.
use strict;
use warnings;
use XML::LibXML;
my $doc = XML::LibXML->load_xml(string => <<'__END_XML__');
<Node>
<NodeX attr1="1" attr2="2" attr3="3"/>
</Node>
__END_XML__
my ($attr) = $doc->findnodes('/Node/NodeX/@attr3');
$attr->setValue(10) if $attr;
print $doc->toString;
output
<?xml version="1.0"?>
<Node>
<NodeX attr1="1" attr2="2" attr3="10"/>
</Node>