J
Jasper2000
Hi,
I'm trying to write a little script that does a query and which
returns XML data. That part is fine, and I thought I'd be okay with
XML::Simple, since I used it a day or two ago, with XML returned from
a different service, and I seemed to understand it fine, and it was
working. However, the XML in this new script is a bit more complex,
and I don't seem to be able to get it working.
Here is the top snippet and first complete "Item" from the XML file:
<SearchSuggestion version="2.0">
<Query xml:space="preserve">Clothes</Query>
<Section>
<Item>
<Text xml:space="preserve">Clothing</Text>
<Description xml:space="preserve">A feature of all modern human
societies....</Description>
<Url xml:space="preserve">http://someurl....</Url>
<Image source="http://someimageurl" width="50" height="33"/>
</Item>
<Item>
<Text xml:space="preserve">Clothes dryer</Text>
<Description xml:space="preserve">
....
....
My snippet of Perl script looks like this:
my $xml = new XML::Simple; # create object
my $data = $xml->XMLin("data.xml");
foreach my $record (@{$data->{Section}->{Item}})
{
print $record->{Text}, "<br />";
}
My output, however, looks like this:
HASH(0x1e35128)<br />HASH(0x1e35374)<br />HASH(0x1e35584)<br /
HASH(0x1e35788)
<br />HASH(0x1e4cfe0)<br />HASH(0x1e4d1e4)<br />HASH(0x1e4d3e8)<br />
HASH(0x1e4d5ec)<br />HASH(0x1e4d748)<br />HASH(0x1e4d8ec)<br />
I've tried various arrangements with the loop, but always seem to end
up with either nothing or something similar to the above.
Any help which can be provided would be most appreciated!
Thanks!
I'm trying to write a little script that does a query and which
returns XML data. That part is fine, and I thought I'd be okay with
XML::Simple, since I used it a day or two ago, with XML returned from
a different service, and I seemed to understand it fine, and it was
working. However, the XML in this new script is a bit more complex,
and I don't seem to be able to get it working.
Here is the top snippet and first complete "Item" from the XML file:
<SearchSuggestion version="2.0">
<Query xml:space="preserve">Clothes</Query>
<Section>
<Item>
<Text xml:space="preserve">Clothing</Text>
<Description xml:space="preserve">A feature of all modern human
societies....</Description>
<Url xml:space="preserve">http://someurl....</Url>
<Image source="http://someimageurl" width="50" height="33"/>
</Item>
<Item>
<Text xml:space="preserve">Clothes dryer</Text>
<Description xml:space="preserve">
....
....
My snippet of Perl script looks like this:
my $xml = new XML::Simple; # create object
my $data = $xml->XMLin("data.xml");
foreach my $record (@{$data->{Section}->{Item}})
{
print $record->{Text}, "<br />";
}
My output, however, looks like this:
HASH(0x1e35128)<br />HASH(0x1e35374)<br />HASH(0x1e35584)<br /
HASH(0x1e35788)
<br />HASH(0x1e4cfe0)<br />HASH(0x1e4d1e4)<br />HASH(0x1e4d3e8)<br />
HASH(0x1e4d5ec)<br />HASH(0x1e4d748)<br />HASH(0x1e4d8ec)<br />
I've tried various arrangements with the loop, but always seem to end
up with either nothing or something similar to the above.
Any help which can be provided would be most appreciated!
Thanks!