From: Jane D. on
Hi,

If somebody can assist me with my query it would be much appreciated.

I'm basically retrieving an XML file from Digg. I can retrieve the
Digg data okay, but am struggling with trying to process the returned
data with Perl, largely on account with my unfamiliarity with XML
processing, but also because I'm not entirely confident with handling
arrays like this. Here's a stripped down version of the main bit of
code:

my $xml = new XML::Simple;
my $data = $xml->XMLin("$diggdata",ForceArray=>1);

foreach my $record (@{$data->{stories}->[0]->{story}})
{
print $record->{title}->[0]->{content};
print $record->{description}->[0]->{content};
# etc, etc, etc
}


The top bit of the XML file looks like this:


<?xml version="1.0" encoding="UTF-8" ?>
- <stories count="10" offset="0" timestamp="1280259772" total="137"
version="1.0">
- <story link="http://www....net/..." submit_date="1280235019"
diggs="1" id="22914259">
<description>Description of story ...</description>
<title>Story title in here</title>
<user icon="/users/eprnetwork/l.png" profileviews="12780"
registered="1170875777" />
<topic name="World News" short_name="world_news" />
<container name="World & Business" short_name="world_business" />
<shorturl short_url="http://digg.com/d31Y92p" view_count="0" />
</story>
- <story link="http://www..." submit_date="1252351084" diggs="2"
id="15603146">
<description>Story 2 description</description>
etc, etc


My issue is that I simply cannot seem to access the data in my loop,
which it does once and then exits (when it should be doing it for each
story). I also tried with ForceArray=0, but same issue. However, the
data in $diggdata is definitely there.

Additionally, I really need to know how to access the attributes of
the XML as well; for example, how to get the "link" attribute, or the
"id" attribute of the <story> tags.

Any help would be much appreciated.

Thanks.

From: Uri Guttman on
>>>>> "JD" == Jane D <janedunnie(a)gmail.com> writes:

JD> my $xml = new XML::Simple;
JD> my $data = $xml->XMLin("$diggdata",ForceArray=>1);

useless use of quotes on the file name.

JD> foreach my $record (@{$data->{stories}->[0]->{story}})
JD> {
JD> print $record->{title}->[0]->{content};
JD> print $record->{description}->[0]->{content};
JD> # etc, etc, etc
JD> }

JD> The top bit of the XML file looks like this:

showing xml data is useless here. use Data::Dumper to see what perl data
you got back from XML::Simple. then you can delve into that with the
proper perl array/hash accessor code.

uri

--
Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: Jane D. on
Yes, but I still need to understand how to process it. I've used
Data::Dumper to see what the data lokos like; I simply don't quite
understand how to access it.

Yes, I've looked in the help files, etc, etc ...

I just need somebody to show me how to do it, if anybody can spare a
few minutes. If not, then I guess I'll head elsewhere.



On Jul 27, 8:51 pm, "Uri Guttman" <u...(a)StemSystems.com> wrote:
> >>>>> "JD" == Jane D <janedun...(a)gmail.com> writes:
>
>   JD> my $xml = new XML::Simple;
>   JD> my $data = $xml->XMLin("$diggdata",ForceArray=>1);
>
> useless use of quotes on the file name.
>
>   JD> foreach my $record (@{$data->{stories}->[0]->{story}})
>   JD> {
>   JD> print $record->{title}->[0]->{content};
>   JD> print $record->{description}->[0]->{content};
>   JD> # etc, etc, etc
>   JD> }
>
>   JD> The top bit of the XML file looks like this:
>
> showing xml data is useless here. use Data::Dumper to see what perl data
> you got back from XML::Simple. then you can delve into that with the
> proper perl array/hash accessor code.
>
> uri
>
> --
> Uri Guttman  ------  u...(a)stemsystems.com  --------  http://www.sysarch.com--
> -----  Perl Code Review , Architecture, Development, Training, Support ------
> ---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com---------

From: Xho Jingleheimerschmidt on
Jane D. wrote:
> Yes, but I still need to understand how to process it.

If you posted "it", we could help you with that.

> I've used
> Data::Dumper to see what the data lokos like; I simply don't quite
> understand how to access it.

But we would understand, if you showed us it.

Xho
From: Uri Guttman on

if you read from top to bottom, you should post that way too.

JD> On Jul 27, 8:51�pm, "Uri Guttman" <u...(a)StemSystems.com> wrote:
>>
>> showing xml data is useless here. use Data::Dumper to see what perl data
>> you got back from XML::Simple. then you can delve into that with the
>> proper perl array/hash accessor code.
>>

>>>>> "JD" == Jane D <janedunnie(a)gmail.com> writes:

JD> Yes, but I still need to understand how to process it. I've used
JD> Data::Dumper to see what the data lokos like; I simply don't quite
JD> understand how to access it.

did you post the dumper data here? why not? i said the xml data is
useless since it is parsed into perl. the perl data is useful. we can't
help you since we can't see the perl data!!

uri

--
Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------