in reply to Re^2: How to fetch the value using LWP:: UserAgent
in thread How to fetch the value using LWP:: UserAgent

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.

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

    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}; }

      As is's said in the module documentation, you can pass the XML directly to XMLin:

      A string of XML A string containing XML (recognised by the presence of '<' and '>' characters) will be parsed directly. eg: $ref = XMLin('<opt username="bob" password="flurp" />');
      my $data = $xml->XMLin($response->decoded_content);

      Using temporary files should be avoided because it's possible race condition.
      Sorry if my advice was wrong.

        Thanks guys...I am done with both the ways I mean using Simple and LibXML

Re^4: How to fetch the value using LWP:: UserAgent
by panapka (Initiate) on Jul 17, 2012 at 07:20 UTC

    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

      Variables are not substituted in single quotes ('). You can use joining operator (.) to join strings together, like this:

      '<?xml version="1.0" encoding ="UTF-8"?><!DOCTYPE drl SYSTEM "http://1 +72.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>'
      You may also want to use some XML generator to generate valid XML in case $id contains special characters, or read about quoting operators.

      # I suggest you to buy a Perl book ("Learning Perl" is very good, for example). Your questions show that there is much room for improvement of your Perl skills.

      Sorry if my advice was wrong.

        @aitap..Thanks and the issue is I used Perl 1.5Years back and this task for 1-2 days..So I have to implement it ASAP..BTW thanks for the advice