iteration has asked for the wisdom of the Perl Monks concerning the following question:
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 }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Accessing node attribute with XML::XPath
by kcott (Archbishop) on Nov 16, 2010 at 21:39 UTC | |
|
Re: Accessing node attribute with XML::XPath
by ikegami (Patriarch) on Nov 16, 2010 at 21:29 UTC | |
by iteration (Initiate) on Nov 16, 2010 at 22:01 UTC | |
|
Re: Accessing node attribute with XML::XPath
by ikegami (Patriarch) on Nov 16, 2010 at 21:31 UTC |