我正在使用 XML::Simple编辑 XML 文件。之后更新的数据被发送到一个新的 XML 文件。但是这个过程会产生 <opt></opt>
要添加的标签,原始父标签丢失。我想替换 <opt>
与原始标签名称。我该怎么做?
最佳答案
参见 KeepRoot .您还应该考虑启用 strict mode .
#!/usr/bin/perl
use strict; use warnings;
use XML::Simple qw(:strict);
use Data::Dumper;
my $x = XMLin(\*DATA, KeepRoot => 1, ForceArray => 1, KeyAttr => ['the']);
print XMLout($x, KeepRoot => 1, KeyAttr => ['the']);
__DATA__
<this>
<that the="other">This that and the other</that>
</this>
输出:
<this>
<that the="other">This that and the other</that>
</this>
关于xml - 如何用原始标签名称替换 XML::Simple 中的 <opt> 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2060971/