I mainly need to know about <body> and <id>, thus using the following:<?xml version="1.0" encoding="UTF-8"?> <recordings type="array"> <recording type="Note"> <author-id type="integer">277210</author-id> <body>Text of the note goes here.</body> <id type="integer">34709871</id> </recording> <recording type="Comment"> <author-id type="integer">277210</author-id> <body>Text of a comment goes here</body> <id type="integer">34719228</id> </recording> </recordings>
I would now also need to access the node attribute ("Note", "Comment") from within the foreach loop. Is there a method for extracting the attribute? Thanks, ~Olivermy $xml = XML::XPath->new (xml => $res->decoded_content); my $nodeset = $xml->find ("/recordings/recording"); foreach my $recording ($nodeset->get_nodelist) { my $id = $recording->find ("id")->string_value (); my $body = $recording->find ("body")->string_value (); # Do something with id and body here }
In reply to Accessing node attribute with XML::XPath by iteration
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |