Click here to get back home

Help in XML::Simple

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Help in XML::Simple amresh 07-01-2005
Posted by amresh on July 1, 2005, 9:12 pm
Please log in for more thread options


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???



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



RESULT
______________________________ Results:


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


Posted by Jim Gibson on July 1, 2005, 9:34 am
Please log in for more thread options



> 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???
>
>
>

You should have here:

use strict;
use warnings;

> use XML::Simple;
> use Data::Dumper;
> $content="<response>

Change the above line to:

my $content ...

> <result>12</result>
> <respmsg>Decline</respmsg>
>
> <authcode>RE-PRESENTED CHK</authcode>
> <pnref>99220</pnref>
> </response>";
> $tags = XMLin($content);

Ditto:

my $tags = ...

> print "\n\nDumper:\n";
> print Dumper($tags);
>
>
>
> RESULT
> ______________________________ Results:
>
>
> Dumper:
> $VAR1 = {
> 'authcode' => 'LREADY USED',
> 'pnref' => '99220',
> 'respmsg' => 'Denied',
> 'result' => '12'___
> 'result' => '12'
> };

This is not what I get when I run your program. You have changed the
authcode from 'LREADY USED' to 'RE-PRESENTED CHK', and I do not get two
'result' entries. Please post exact code and output from your program
so you don't confuse those trying to help you.

The $VAR1 is a name picked by the Data::Dumper module. This is
explained in the documentation for Data::Dumper, although perhaps not
so clearly as it could be. Have you read the documentation for
Data::Dumper? If you want a more explicit output format, you can use
the following:

print Data::Dumper->Dump([$tags], [qw(tags)]);

as explained in the documentation for Data::Dumper.

XMLin returns a reference to a hash. There are examples of how to
access the data in the documentation for XML::Simple. Have you read the
documentation for XML::Simple?

As an example in your case, the authcode entry is $.


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000
Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


Posted by Iain Chalmers on July 5, 2005, 12:33 pm
Please log in for more thread options



>
> > 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???
>
> As an example in your case, the authcode entry is $

Or, since that syntax makes me wince, $tags->

"There's more than one way to do it"

big
--
On my tombstone they will carve, "IT NEVER GOT FAST
ENOUGH FOR ME."' - Hunter S Thompson, 1937-2005 RIP


Similar ThreadsPosted
XML::Simple Help? April 23, 2005, 5:09 pm
Getopt::Simple V 1.47 July 29, 2004, 7:18 am
Simple question September 15, 2005, 4:17 am
Filter::Simple bug? December 21, 2004, 9:54 pm
LWP::Simple getstore January 6, 2005, 7:52 pm
Parallel::Simple February 25, 2005, 11:25 pm
[RFC] XML::Simple::Tree November 3, 2005, 11:37 pm
Expect::Simple December 1, 2005, 4:19 pm
Expect::Simple December 2, 2005, 9:22 am
XML::Simple Problem February 16, 2006, 5:13 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap