XML::简单且唯一的名称
我很难制作一个 Perl 脚本来正确解析如下所示的 XML 文件:
<Report name="NAME">
<ReportHost name="UNIQUE_1"><HostProperties>
<tag name="TAG_1">tag_value</tag>
<tag name="TAG_2">tag_value</tag>
</ReportHost>
<ReportHost name="UNIQUE_2"><HostProperties>
<tag name="TAG_1">tag_value</tag>
<tag name="TAG_2">tag_value</tag>
</ReportHost>
现在,我需要能够以某种方式调用这些 UNIQUE_n,但我无法管理。 Dumper 返回如下结构:
'Report' => {
'ReportHost' => {
'UNIQUE_1' => {
'HostProperties' => {
'tag' => { [...]
我尝试了 ForceArray,但无法使 ReportHost 成为数组并惨败。
I'm having a hard time making a Perl script to correctly parse an XML file which looks like the following:
<Report name="NAME">
<ReportHost name="UNIQUE_1"><HostProperties>
<tag name="TAG_1">tag_value</tag>
<tag name="TAG_2">tag_value</tag>
</ReportHost>
<ReportHost name="UNIQUE_2"><HostProperties>
<tag name="TAG_1">tag_value</tag>
<tag name="TAG_2">tag_value</tag>
</ReportHost>
Now, I need to be able to call those UNIQUE_n somehow, but I couldn't manage. Dumper returns a structure like the following:
'Report' => {
'ReportHost' => {
'UNIQUE_1' => {
'HostProperties' => {
'tag' => { [...]
I tried ForceArray, but couldn't make ReportHost an array and failed miserably.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你说你在让 Perl“正确解析”XML 时遇到困难,但你没有说你想要什么样的结果。抛开您的示例 XML 缺少一些结束标记这一事实不谈,也许您想要这样的内容:
这给出了:
您可以像这样循环访问数据:
我会推荐 使用不同的模块:-)
You say you're having trouble getting Perl to "correctly parse" the XML But you don't say what sort of result you want. Putting aside the fact that your example XML is missing some closing tags, perhaps you're wanting something like this:
Which gives:
And you could loop through the data like this:
I would recommend using a different module though :-)