in reply to How to fetch the value using LWP:: UserAgent

You're looking for an XML parser.
use XML::LibXML qw(); my $dom = XML::LibXML->load_xml(string => \<<'XML'); <drl connectionid="foobar" /> XML for my $node ($dom->findnodes('//drl[@connectionid]')) { print $node->getAttribute('connectionid'); }

Replies are listed 'Best First'.
Re^2: How to fetch the value using LWP:: UserAgent
by panapka (Initiate) on Jul 16, 2012 at 11:54 UTC

    I tried with following code

    my $dom = XML::LibXML->load_xml(string => <<'XML'); <$response->decoded_content/> XML for my $node ($dom->findnodes('//drl[@connectionid]')) { print $node->getAttribute('connectionid');

    it is throwing the error, what is wrong here

      Your try to use here-doc there was wrong. Just pass the decoded_content as the value of "string": my $dom = XML::LibXML->load_xml(string => $response->decoded_content);
      Sorry if my advice was wrong.

        I am Done but using Simple module

        if ($response->is_success) { my $data = $response->decoded_content; open (MYFILE, '>>data.xml'); print MYFILE "$data"; close MYFILE; my $xml = new XML::Simple; my $data1 = $xml->XMLin("data.xml"); print $data1->{connectionid}; }

        Again its troubling on one place

         my $xml = '<?xml version="1.0" encoding ="UTF-8"?><!DOCTYPE drl SYSTEM "http://172.XX.XXX.XXX:40500/lab/api/reserveRequest.dtd"><drl mode="normal" id="$Id"><id="1009"><attributes><attribute name="Clust" link="true" category="INV"><value>8</value></attribute></attributes></drl>';

        Here $Id is I am getting from another request and its declared globally but as request is in single quote it wont be able to get the value of $id , I have to use escape character or some interpolation method, tried a lot but vain..Can any one help