Search code examples
xmlperllibxml2xml-libxml

Accessing nodes in Perl libXML


I have the following Perl code, I am using LibXML:

 my @childnodes = $node1->childNodes();
 my $node2 = @childnodes->getNode(1); # Access first child node

What I want to do is to access the nodes obtained by childNodes() individually but my $node2 = @childnodes->getNode(1); doesn't work. How can this be done?


Solution

  • @childNodes is an array of nodes. Just treat it like any other array.

    my $node2 = $childnodes[0]; # Access first child node