Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Retrieving an XML node value with XML::DOM::Lite and XML::Parser

by Eliya (Vicar)
on Dec 18, 2013 at 18:43 UTC ( #1067675=note: print w/replies, xml ) Need Help??


in reply to Retrieving an XML node value with XML::DOM::Lite and XML::Parser

From a quick look at the source of XML/DOM/Lite/Document.pm, I'd say you need

my $B = $doc->selectNodes("A/B")->[$cpt]->nodeValue(); my $D = $doc->selectNodes("A/C/D")->[$cpt]->nodeValue();

i.e. selectNodes returns an arrayref, not an object.

Other than that, you could make your loop look more "perly", by writing

if(defined($A_list)){ for my $cpt (0..$#$A_list) { ... } print "\n\n"; }

That said, wouldn't it be easier to just iterate over the arrays returned by selectNodes, and call ->nodeValue on each element, instead of selecting the elements by index from the (same) result list that you retrieve over and over again (the xpath query yields the same result on every iteration of the loop).

Replies are listed 'Best First'.
Re^2: Retrieving an XML node value with XML::DOM::Lite and XML::Parser
by young_monk_love_perl (Novice) on Dec 18, 2013 at 21:46 UTC

    As I replied to roboticus, I'm getting an error when I try to print the value, but using the debug statements roboticus provided, i can get an Array reference.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1067675]
help
Chatterbox?
usemodperl thinks every1 should serve HTTP on port 80 incase we don't care about encryption, right? wtf

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2018-06-24 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (126 votes). Check out past polls.

    Notices?