were using the XML/Simple module to process a XML response using the code below.
But for some reason the module can't read the $xmlresponse data unless we create
a temp file first to store the data then pass that to the module. Is there a way
to do this without having to create a temp file first. ?? Everything does work,
the response is return. We used the Data/Dumper module to verify the data first.
=========================================================
my $ua = new LWP::UserAgent;
$ua->timeout(10);
$ua->agent("HTTP/1.1");
my $req = new HTTP::Request 'POST' => "$xmlscript";
$req->content_type("application/x-www-form-urlencoded");
$req->content($xmlrequest);
my $res = $ua->request($req);
my $error = $res->is_error();
my $success = $res->is_success();
# Data returned in XML Format
my $xmlresponse = $res->content();
my $simple = new XML::Simple(KeyAttr=>[]);
# read XML file
my $xmldata = $simple->XMLin("$xmlresponse");
# can't read the response in this manner
===================================================
Thanks and happy holidays,
Mike(mickalo)Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
http://www.thunder-rain.com/
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> were using the XML/Simple module to process a XML response using the code
> below. But for some reason the module can't read the $xmlresponse data
> unless we create a temp file first to store the data then pass that to the
> module. Is there a way to do this without having to create a temp file
> first. ?? Everything does work, the response is return. We used the
> Data/Dumper module to verify the data first.
>
> =========================================================
> my $ua = new LWP::UserAgent;
> $ua->timeout(10);
> $ua->agent("HTTP/1.1");
> my $req = new HTTP::Request 'POST' => "$xmlscript";
> $req->content_type("application/x-www-form-urlencoded");
> $req->content($xmlrequest);
> my $res = $ua->request($req);
>
> my $error = $res->is_error();
> my $success = $res->is_success();
>
> # Data returned in XML Format
> my $xmlresponse = $res->content();
>
> my $simple = new XML::Simple(KeyAttr=>[]);
> # read XML file
> my $xmldata = $simple->XMLin("$xmlresponse");
> # can't read the response in this manner
> ===================================================
>
Try the "parse_string" method instead. The documentation says that XMLin
guesses based on the presence of "<" and ">" characters. It appears that
XMLin guesses wrong in your case.
"parse_string" explicitly expects an XML string. So there's no logic to
confuse.
--
Robert Wohlfarth
Thanks Robert, that did the trick :)
Mike(mickalo)Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Custom Programming & Web Hosting Services
http://www.thunder-rain.com/
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
DO NOT QUOTE VARIABLES!
If the $variable already contains a string, you just unnecessary make
a copy. If it contains a number (well it can contain both, but I mean
the case when it contains just the number), you force Perl to convert
the number to string (and store that string alongside the number in
the variable) and make a copy of the string. And possibly later it
will have to convert the string back to number.
And these are the cases when it actually works, even if it's
inefficient. As soon as you quote like this a variable that contains
a reference or an object (a reference bless()ed to a package), you
end up with useles string, that will just look like a reference when
printed out. Do not quote variables!
my $req = new HTTP::Request 'POST' => $xmlscript;
is enough!
> my $simple = new XML::Simple(KeyAttr=>[]);
> # read XML file
> my $xmldata = $simple->XMLin("$xmlresponse");
OK, you are safe from automatic key related transformations ... what
about tags with optional attributes? Or tags that are sometimes but
not always repeated?
See http://www.perlmonks.org/?node_id=697036
Jenda
===== Je...@Krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
Jenda,
thanks for the info, I nomarlly don't quote variables like that, just didn't
catch that one.