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

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.
  • Comment on Re^2: XML::LibXML drives me to drinking

Replies are listed 'Best First'.
Re^3: XML::LibXML drives me to drinking
by Your Mother (Archbishop) on Oct 23, 2016 at 03:40 UTC

    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!