我正在尝试使用 Perl 更改 XML 属性。
XML 文件如下所示:
<Node>
<NodeX attr1="1" attr2="2" attr3="3"/>
</Node>
Perl 脚本包含:
my @nodes = $doc->findnodes("//Node/Nodex");;
if (@nodes) {
my $res = $nodes[0]->hasAttribute("attr3");
if ($res) {
foreach (@nodes) {
$_->setAttribute('attr3', "10");
}
}
}
结果,脚本不会更改属性。我已经测试了权限,脚本可以使用print
.
setAttribute
hasAttribute
尽管返回 true ,但似乎什么也没做。