[英]How to find child elements of a specified parent using XML::LibXML?
Suppose I have a XML file 假设我有一个XML文件
<table>
<person>
<ID>1</ID>
<Name>Adam</Name>
</person>
<student>
<Subject>Math</Subject>
<Marks>90</Marks>
</student>
<employee>
<ID>7</ID>
<Name>Bill</Name>
</employee>
</table>
I want to get the child elements of the table
element. 我想获取table
元素的子元素。 ie the output should be person
, student
and employee
. 即输出应该是person
, student
和employee
。 How do I do this with the XML::LibXML
module in Perl? 我该如何在Perl中使用XML::LibXML
模块?
for my $node ($doc->findnodes('/table/*')) {
say $node->nodeName();
}
or 要么
use XML::LibXML qw( XML_ELEMENT_NODE );
my $root = $doc->documentElement();
for my $node ( grep { $_->nodeType() == XML_ELEMENT_NODE } $root->childNodes() ) {
say $node->nodeName();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.