Perl使用XML Path Context来提取数据

Sam*_*ron 3 perl xml-parsing xml-libxml

我有以下xml

<?xml version="1.0" encoding="utf-8"?>
<Response>
   <Function Name="GetSomethingById">
      <something idSome="1" Code="1" Description="TEST01" LEFT="0" RIGHT="750" />
   </Function>
</Response>
Run Code Online (Sandbox Code Playgroud)

我希望<something>节点的属性作为哈希.我试着像下面

my $xpc = XML::LibXML::XPathContext->new(
    XML::LibXML->new()->parse_string($xml)   # $xml is containing the above xml
);
my @nodes = $xpc->findnodes('/Response/Function/something');
Run Code Online (Sandbox Code Playgroud)

我希望有$nodes[0]->getAttributes任何帮助吗?

ike*_*ami 5

my %attributes = map { $_->name => $_->value } $node->attributes();
Run Code Online (Sandbox Code Playgroud)