Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: XML::LibXML drives me to drinking

by tunafish (Beadle)
on Oct 23, 2016 at 03:59 UTC ( #1174535=note: print w/replies, xml ) Need Help??


in reply to Re: XML::LibXML drives me to drinking
in thread XML::LibXML drives me to drinking

Wait, are you saying I need to create a new XML::LibXML::XPathContext object for each node as I loop through them?!

I modified my code in the following way:

# Parse items foreach my $item ($xml->findnodes('/x:ItemLookupResponse/x:Items/x:Ite +m', $parser)){ my $item_xml = XML::LibXML::XPathContext->new($item); $item_xml->registerNs('x', 'http://webservices.amazon.com/AWSE +CommerceService/2013-08-01'); print $item_xml->findvalue('x:ASIN'), "\n"; print $item_xml->findnodes('x:ASIN')->shift->textContent, "\n" +; }

And bingo!

B01KI4JSQY B01KI4JSQY

Oy vey! Wouldn't it be much more convenient if a XML::LibXML::XPathContext object calling the findnodes() method returned another XML::LibXML::XPathContext object, rather than a XML::LibXML::Node or XML::LibXML::Element object?

I haven't pulled this much hair in one day for a coding-related reason IN YEARS.

Replies are listed 'Best First'.
Re^3: XML::LibXML drives me to drinking
by Anonymous Monk on Oct 23, 2016 at 05:00 UTC

    Wait, are you saying I need to create a new XML::LibXML::XPathContext object for each node as I loop through them?!

    No, what gave you that idea?

    All XML::LibXML::XPathContext does is map prefixes to namespaces, and that only needs to be done once.

    See https://metacpan.org/pod/XML::LibXML::Node#findnodes

    I haven't pulled this much hair in one day for a coding-related reason IN YEARS.

    step away from the keyboard, lunch, nap, vacation, whatever it takes

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1174535]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2020-04-03 18:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The most amusing oxymoron is:
















    Results (31 votes). Check out past polls.

    Notices?