#Open and parse XML open (my $input, "new(); my $pdoc = $parser->parse_file('xmlsample.xml'); close ($input) or die "Could not close xml input."; #Register Namespace my $rdoc = XML::LibXML::XPathContext->new($pdoc->documentElement()); $rdoc->registerNs( ns => 'bazongNS' ); #Find node and add element my ($object) = $rdoc->findnodes("\/\/ns:root"); $object->addNewChild("bazongNS","element"); #Replace file open (my $OutputXML, ">xmlsample.xml") or die "Could not write XML file."; print $OutputXML $pdoc->toString(); close ($OutputXML) or die "Could not close written XML file."; #### ####