in reply to XML::LibXML drives me to drinking

I’m not free to write more this moment but this might have enough to get you sorted: Re^3: Anyone Have Perl Code for New Amazon API? [SOLVED]. If not, or no one else steps in, I’ll write more in a day or two.

Replies are listed 'Best First'.
Re^2: XML::LibXML drives me to drinking
by tunafish (Beadle) on Oct 23, 2016 at 03:15 UTC
    Unfortunately not. This gets me to the point at which I am already (and what a struggle THAT was!) but I can already access nodes from the root level. Now, however, I need to access named sub-nodes of a particular node (in my example, ASIN of /ItemLookupResponse/Items/Item). It's not really helpful to access it from root (/ItemLookupResponse/Items/Item/ASIN) because there may be several Item nodes.

      My node had pretty good clues, actually. :P Try this–

      use strict; use XML::LibXML; my $string = <<""; <?xml version="1.0"?> <ItemLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceS +ervice/2013-08-01"> <Items> <Item> <ASIN>B01KI4JSQY</ASIN> </Item> </Items> </ItemLookupResponse> my $doc = XML::LibXML->new->load_xml(string => $string, {no_blanks => +1}); my $xc = XML::LibXML::XPathContext->new($doc); $xc->registerNs( x => $doc->getDocumentElement->namespaceURI ); for my $item ( $xc->findnodes('//x:ItemLookupResponse/x:Items/x:Item') + ) { print $item->firstChild->nodeName, "\n"; print $item->firstChild->toString, "\n"; print $xc->findvalue('x:ASIN', $item), "\n"; }
        And LIKE THAT, it all clicks into place for me. THANK YOU!