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