我想追加<value></value>
之間的字符串,附加價值XML節點用perl
<?xml version="1.0" encoding="UTF-8"?>
<rs:alarm-request throttlesize="100" xmlns:rs="http://url.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.url.com">
<rs:attribute-filter>
<search-criteria xmlns="http://www.url">
<filtered-models>
<equals>
<attribute id="0x1144f50">
<value></value>
</attribute>
</equals>
</filtered-models>
</search-criteria>
</rs:attribute-filter>
<!-- Models of Interest -->
<rs:target-models>
</rs:target-models>
</rs:alarm-request>
我用下面的代碼,但我不斷收到: 無法找到對象的方法「appendTextNode 「via package」XML :: LibXML :: NodeList「
my $parser = XML::LibXML->new();
# Insert devices MH to GETdevices_xmlbody template
my $doc = $parser->parse_file($current_working_dir.'\GETdevices_xmlbody.xml');
my $elem = $doc->findnodes('//rs:attribute-filter/search-criteria/filtered-models/equals/attribute/value');
# $elem->removeChildNodes();
$elem->appendTextNode('STRING');
如果你的XPath匹配,那麼你可以使用像'$ elem-> get_node(1) - > appendTextNode('STRING');' –