xml - 如何用原始标签名称替换 XML::Simple 中的 <opt> 标签?

标签 xml perl xml-simple

我正在使用 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/

相关文章:

xml - 如何使用 Golang 获取 XML 中深层元素的元素名称

android - 在抽屉菜单上设置可见性

javascript - 在以编程方式创建的 div 上应用 css 规则

sql-server - 只能从 xml 变量中获取标签下的第一条记录

perl - 使用 Perl 同时创建 ZIP 存档和文件

perl - 加载 Perl 的线程模块时如何修复 Bootstrap 版本不匹配的问题?

json - 使用 perl 将 JSON::PP::Boolean 转换为 0,1 的正确且简单的方法

Android,帮助解决 simpleframework PersistenceException

ruby - 如何使用 XmlSimple 生成带有属性和文本节点的 XML 元素?