如何处理同名的子节点?
我有包含 1000 个实体的 xml,如下面的模板:
<data>
<row> ded</row>
<row> def </row>
<row> fff </row>
<row> fff </row>
</data>
我需要使用 XML::Twig 来解析它。
我使用以下代码:
my $twig = XML::Twig->new(
twig_handlers => {
data => sub {
my $x1 = $_->first_child_trimmed_text('row');
print $x1;
#I need also here to run over the other rows and extract them
}
} );
如何遍历行并提取它们(它们具有相同的名称)?
I have xml with the 1000 entities like the below template :
<data>
<row> ded</row>
<row> def </row>
<row> fff </row>
<row> fff </row>
</data>
I need to parse it with XML::Twig.
I use the following code:
my $twig = XML::Twig->new(
twig_handlers => {
data => sub {
my $x1 = $_->first_child_trimmed_text('row');
print $x1;
#I need also here to run over the other rows and extract them
}
} );
How can I run over the rows and extract them (they have the same name)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 XML::Twig 方法
children_trimmed_text()
< /a> - 它会给你一个子列表,然后你可以对其进行迭代。像这样的东西:You can use the XML::Twig method
children_trimmed_text()
- it'll give you a list of the children, which you can then iterate over. Something like this: