Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl using XML Path Context to extract out data

I have the following 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>

and I want the attributes of <something> node as a hash. Im trying like below

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');

Im expecting to have something like $nodes[0]->getAttributes, any help?

like image 315
Samiron Avatar asked Dec 07 '25 14:12

Samiron


1 Answers

my %attributes = map { $_->name => $_->value } $node->attributes();
like image 110
ikegami Avatar answered Dec 10 '25 04:12

ikegami



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!