Click here to get back home

Perl XML::Simple Accessing complex XML

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    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
Perl XML::Simple Accessing complex XML zzapper 06-18-2008
Get Chitika Premium
Posted by zzapper on June 18, 2008, 8:05 am
Please log in for more thread options
Hi
<companyname count="1">
<property id="55467" md="2008-03-20" mc="GBP" mp="173000" >
<psumm><![CDATA[This 3 bedroom, ]]></psumm>
<a1>1 Bucket Way</a1>
<at>Stafford</at>
<ac>Staffordshire</ac>
<actry></actry>
<images>
<image id="543">Property Image</image>
<image id="545">Property Image</image>
</images>
</property>
</companyname>

I am trying to read the above (simplified) with XML::Simple with or
without ForceArray=1.

I can output everything EXCEPT I cannot find the Perl data syntax to
access anything in <images> eg 543 or
the text "Property Image"

$data = $xml->XMLin("prop.xml", forcearray => 1);
$ac=$data->->->[0];

Desperate!!
zzapper




Posted by John on June 18, 2008, 8:39 am
Please log in for more thread options

> Hi
> <companyname count="1">
> <property id="55467" md="2008-03-20" mc="GBP" mp="173000" >
> <psumm><![CDATA[This 3 bedroom, ]]></psumm>
> <a1>1 Bucket Way</a1>
> <at>Stafford</at>
> <ac>Staffordshire</ac>
> <actry></actry>
> <images>
> <image id="543">Property Image</image>
> <image id="545">Property Image</image>
> </images>
> </property>
> </companyname>
>
> I am trying to read the above (simplified) with XML::Simple with or
> without ForceArray=1.
>
> I can output everything EXCEPT I cannot find the Perl data syntax to
> access anything in <images> eg 543 or
> the text "Property Image"
>
> $data = $xml->XMLin("prop.xml", forcearray => 1);
> $ac=$data->->->[0];
>
> Desperate!!
> zzapper

Hi

With ForceArray turned on.

my $temp=$data->->[0]->->[0]->->[0]; # id of
first image
$temp=$data->->[0]->->[0]->->[1]; # id of
second image
$temp=$data->->[0]->->[0]->->[0]; #
Property Image of first image
$temp=$data->->[0]->->[0]->->[1]; #
Property Image of second image

Regards
John



Posted by zzapper on June 18, 2008, 9:06 am
Please log in for more thread options
>
>
>
>
> > Hi
> > <companyname count=3D"1">
> > <property id=3D"55467" md=3D"2008-03-20" mc=3D"GBP" mp=3D"173000" >
> > <psumm><![CDATA[This 3 bedroom, ]]></psumm>
> > <a1>1 Bucket Way</a1>
> > <at>Stafford</at>
> > <ac>Staffordshire</ac>
> > <actry></actry>
> > <images>
> > =A0 =A0 <image id=3D"543">Property Image</image>
> > =A0 =A0 <image id=3D"545">Property Image</image>
> > </images>
> > </property>
> > </companyname>
>
> > I am trying to read the above (simplified) with XML::Simple with or
> > without ForceArray=3D1.
>
> > I can output everything EXCEPT I cannot find the Perl data syntax to
> > access anything in <images> eg =A0543 or
> > the text "Property Image"
>
> > $data =3D $xml->XMLin("prop.xml", forcearray =3D> 1);
> > $ac=3D$data->->->[0];
>
> > Desperate!!
> > zzapper
>
> Hi
>
> With ForceArray turned on.
>
> my $temp=3D$data->->[0]->->[0]->->[0]; # id =
of
> first image
> $temp=3D$data->->[0]->->[0]->->[1]; # id of
> second image
> $temp=3D$data->->[0]->->[0]->->[0]; #
> Property Image of first image
> $temp=3D$data->->[0]->->[0]->->[1]; #
> Property Image of second image
>
> Regards
> John

Hi John
Unfortunately this didn't work for me, the output was blank.
zzapper

Posted by Jim Gibson on June 18, 2008, 3:33 pm
Please log in for more thread options
In article

> >
> >
> >
> >
> > > Hi
> > > <companyname count="1">
> > > <property id="55467" md="2008-03-20" mc="GBP" mp="173000" >
> > > <psumm><![CDATA[This 3 bedroom, ]]></psumm>
> > > <a1>1 Bucket Way</a1>
> > > <at>Stafford</at>
> > > <ac>Staffordshire</ac>
> > > <actry></actry>
> > > <images>
> > >     <image id="543">Property Image</image>
> > >     <image id="545">Property Image</image>
> > > </images>
> > > </property>
> > > </companyname>
> >
> > > I am trying to read the above (simplified) with XML::Simple with or
> > > without ForceArray=1.
> >
> > > I can output everything EXCEPT I cannot find the Perl data syntax to
> > > access anything in <images> eg  543 or
> > > the text "Property Image"
> >
> > > $data = $xml->XMLin("prop.xml", forcearray => 1);
> > > $ac=$data->->->[0];
> >
> > > Desperate!!
> > > zzapper
> >
> > Hi
> >
> > With ForceArray turned on.
> >
> > my $temp=$data->->[0]->->[0]->->[0]; # id of
> > first image
> > $temp=$data->->[0]->->[0]->->[1]; # id of
> > second image
> > $temp=$data->->[0]->->[0]->->[0]; #
> > Property Image of first image
> > $temp=$data->->[0]->->[0]->->[1]; #
> > Property Image of second image
> >
> > Regards
> > John
>
> Hi John
> Unfortunately this didn't work for me, the output was blank.
> zzapper

Try:

$data->->->->[0]->->->

To figure these things out, use the Data::Dumper module to reveal the
structure of the data returned by XMLin:

print Dumper($data);

--
Jim Gibson

Posted by zzapper on June 18, 2008, 5:50 pm
Please log in for more thread options
> In article
>
>
>
>
...
>
> > > > Hi
> > > > <companyname count=3D"1">
> > > > <property id=3D"55467" md=3D"2008-03-20" mc=3D"GBP" mp=3D"173000" >
> > > > <psumm><![CDATA[This 3 bedroom, ]]></psumm>
> > > > <a1>1 Bucket Way</a1>
> > > > <at>Stafford</at>
> > > > <ac>Staffordshire</ac>
> > > > <actry></actry>
> > > > <images>
> > > > =A0 =A0 <image id=3D"543">Property Image</image>
> > > > =A0 =A0 <image id=3D"545">Property Image</image>
> > > > </images>
> > > > </property>
> > > > </companyname>
>
> > > > I am trying to read the above (simplified) with XML::Simple with or
> > > > without ForceArray=3D1.
>
> > > > I can output everything EXCEPT I cannot find the Perl data syntax t=
o
> > > > access anything in <images> eg =A0543 or
> > > > the text "Property Image"
>
> > > > $data =3D $xml->XMLin("prop.xml", forcearray =3D> 1);
> > > > $ac=3D$data->->->[0];
>
> > > > Desperate!!
> > > > zzapper
>
> > > Hi
>
> > > With ForceArray turned on.
>
> > > my $temp=3D$data->->[0]->->[0]->->[0]; #=
id of
> > > first image
> > > $temp=3D$data->->[0]->->[0]->->[1]; # id=
of
> > > second image
> > > $temp=3D$data->->[0]->->[0]->->[0];=
#
> > > Property Image of first image
> > > $temp=3D$data->->[0]->->[0]->->[1];=
#
> > > Property Image of second image
>
> > > Regards
> > > John
>
> > Hi John
> > Unfortunately this didn't work for me, the output was blank.
> > zzapper
>
> Try:
>
> $data->->->->[0]->->->
>
> To figure these things out, use the Data::Dumper module to reveal the
> structure of the data returned by XMLin:
>
> print Dumper($data);
>
> --
> Jim Gibson
Great that worked.
I've now tried an alternative
$data =3D $xml->XMLin("prop.xml", KeyAttr =3D> {images =3D> 'image'});
Which works if don't use forcearray.

gives me

'images' =3D> {
'image' =3D> [
{
'content' =3D>
'Property Image',
'id' =3D> '2410543'
},
{
'content' =3D>
'Property Image',
'id' =3D> '2410544'
},
{
'content' =3D>
'Property Image',
'id' =3D> '2410545'
}
]


zzapper

Similar ThreadsPosted
How to call a simple perl script from HTML without need of HTTPS but simple HTTP ? May 11, 2006, 4:37 am
Complex problem I need to solve with perl February 22, 2006, 2:57 pm
Perl ODBC complex query example needed March 21, 2005, 4:01 pm
Perl Complex Data Structure Parsing December 3, 2006, 1:56 pm
Accessing Single Parameters in Perl Script March 23, 2005, 3:41 pm
Accessing TestDirector for Quality Center OTA API using Perl May 3, 2006, 3:53 pm
Perl module for accessing dbase files November 1, 2007, 8:16 pm
Accessing Public Folders of Exchange 2003/2007 using Perl Scripts January 10, 2007, 5:36 am
Complex Records help September 1, 2004, 4:47 am
complex numbers January 9, 2005, 1:36 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap