J
Jane D.
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.
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.