For Programmers: Free Programming Magazines  


Home > Archive > PERL Modules > April 2005 > XML::Simple Help?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author XML::Simple Help?
Vin Grover

2005-04-23, 8:55 pm


I'm looking for a simple way to process results returned from a
website via XML. I was thinking XML::Simple should be simple... but
apparently I'm even simpler than it is!

I'm having trouble figuring out how to get at the four items it
returns. Looks like $tags contains a hash which is actually a data
structure named $VAR1, which appears to define a hash, but how do I
make it work? It looked empty, but Dumper shows the contents and they
look like exactly what I want... but how do I access it???

-----------------------------------
Test Code (response is copied from actual data):

#!/usr/bin/perl

use XML::Simple;
use Data::Dumper;
$content="<response>
<result>12</result>
<respmsg>Decline</respmsg>
<authcode>RE-PRESENTED CHK</authcode>
<pnref>99220</pnref>
</response>";
$tags = XMLin($content);
print "\n\nDumper:\n";
print Dumper($tags);

-----------------------------------
Results:


Dumper:
$VAR1 = {
'authcode' => 'LREADY USED',
'pnref' => '99220',
'respmsg' => 'Denied',
'result' => '12'
};
-----------------------------------

So... $tags contains what I'm looking for... now I need to be able to
use the four items!

Anyone?

Vin Grover

2005-04-23, 8:55 pm

Vin Grover <grover037@hottttmail.com> wrote on Sat, 23 Apr 2005
16:09:29 -0500:

As usually happens, after giving up and begging for help, I promptly
found the answer...

$content->{result} etc...


duhhhh...


>
>I'm looking for a simple way to process results returned from a
>website via XML. I was thinking XML::Simple should be simple... but
>apparently I'm even simpler than it is!
>
>I'm having trouble figuring out how to get at the four items it
>returns. Looks like $tags contains a hash which is actually a data
>structure named $VAR1, which appears to define a hash, but how do I
>make it work? It looked empty, but Dumper shows the contents and they
>look like exactly what I want... but how do I access it???
>
>-----------------------------------
>Test Code (response is copied from actual data):
>
>#!/usr/bin/perl
>
>use XML::Simple;
>use Data::Dumper;
>$content="<response>
> <result>12</result>
> <respmsg>Decline</respmsg>
> <authcode>RE-PRESENTED CHK</authcode>
> <pnref>99220</pnref>
> </response>";
>$tags = XMLin($content);
>print "\n\nDumper:\n";
>print Dumper($tags);
>
>-----------------------------------
> Results:
>
>
>Dumper:
>$VAR1 = {
> 'authcode' => 'LREADY USED',
> 'pnref' => '99220',
> 'respmsg' => 'Denied',
> 'result' => '12'
> };
>-----------------------------------
>
>So... $tags contains what I'm looking for... now I need to be able to
>use the four items!
>
>Anyone?


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com