1

正如标题所说,我只是想遍历每个文本节点并搜索和替换一个值。如何使用 XML::LibXML 做到这一点?

use warnings;
use strict;
use XML::LibXML qw(XML_ELEMENT_NODE XML_ATTRIBUTE_NODE XML_TEXT_NODE);

my $parser = XML::LibXML->new({keep_blanks => 0 });
my $dom = $parser->load_xml(location => 'walkDOM.xml') or die;

foreach my $fndval2 ($dom->findnodes('//*'))
{
 foreach my $child ( $fndval2->getChildnodes()) 
 {
  if ($child->nodeType eq 3)  **# still can't figure-out how to use keyword instead** 
  {
   **<<  right here I like to search/grep for value and replace >>**   
   print "NodeName: ", $fndval2->nodeName(), " VALUE: ", $child->textContent, "\n";
  }
 }
}
4

0 回答 0