我有以下 XML 文件:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="CoreNLP-to-HTML.xsl" type="text/xsl"?>
<root>
<document>
<sentences>
<sentence id="1">
<basic-dependencies>
<dep type="nn">
<governor idx="2">Planted</governor>
<dependent idx="1">Europeans</dependent>
</dep>
</basic-dependencies>
</sentence>
</sentences>
</document>
</root>
我可以使用下面给出的代码提取内容“欧洲人”。有什么方法可以使用 XML::LibXML 从标签中提取“nn”?
use strict;
use warnings;
use XML::LibXML qw( );
my $output = $filename.'.xml';
my $parser = XML::LibXML->new();
my $doc = $parser->parse_file($output);
for my $dependency_node ($doc->findnodes('//document/sentences/sentence/basic-dependencies'))
{
for my $dependent_node ($dependency_node->findnodes('dep'))
{
my $word = $dependent_node->findvalue('dependent/text()');
print "$word\n";
}
}