![](/img/trans.png)
[英]Using XML::LibXML: How do I create namespaces and child elements and make them work together?
[英]How to find child elements of a specified parent using XML::LibXML?
假設我有一個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>
我想獲取table
元素的子元素。 即輸出應該是person
, student
和employee
。 我該如何在Perl中使用XML::LibXML
模塊?
for my $node ($doc->findnodes('/table/*')) {
say $node->nodeName();
}
要么
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.