gpt4 book ai didi

perl - XML::Simple 删除根元素

转载 作者:行者123 更新时间:2023-12-02 08:45:12 24 4
gpt4 key购买 nike

嗨,我有一个从哈希数组中获取的 xml 数据,当我对其执行 Dumper 时,输出如下:

$var1=
'<Data>
<Data1>ABC</Data1>
<Data2>ABCD</Data2>
</Data>';

我将其放在变量调用 $var1 中。现在我在上面使用 XML::Simple ..它有点像: {Data1=>'ABC',Data2=>'ABCd'};

第一个标签数据消失了。怎么了?

最佳答案

似乎是well-documented :

KeepRoot => 1:

In its attempt to return a data structure free of superfluous detail and unnecessary levels of indirection, XMLin() normally discards the root element name. Setting the KeepRoot option to 1 will cause the root element name to be retained. So after executing this code:

     $config = XMLin('<config tempdir="/tmp" />', KeepRoot => 1)

You'll be able to reference the tempdir as "$config->{config}->{tempdir}" instead of the default "$config->{tempdir}".

关于perl - XML::Simple 删除根元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14542475/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com