Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Perl XML::Simple Accessing complex XML

Reply
Thread Tools

Perl XML::Simple Accessing complex XML

 
 
zzapper
Guest
Posts: n/a
 
      06-18-2008
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->{property}->{554674}->{ac}[0];

Desperate!!
zzapper



 
Reply With Quote
 
 
 
 
John
Guest
Posts: n/a
 
      06-18-2008

"zzapper" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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->{property}->{554674}->{ac}[0];
>
> Desperate!!
> zzapper


Hi

With ForceArray turned on.

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

Regards
John


 
Reply With Quote
 
 
 
 
zzapper
Guest
Posts: n/a
 
      06-18-2008
On Jun 18, 1:39*pm, "John" <(E-Mail Removed)> wrote:
> "zzapper" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
> > 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->{property}->{554674}->{ac}[0];

>
> > Desperate!!
> > zzapper

>
> Hi
>
> With ForceArray turned on.
>
> my $temp=$data->{property}->[0]->{images}->[0]->{image}->[0]{id}; # id of
> first image
> $temp=$data->{property}->[0]->{images}->[0]->{image}->[1]{id}; # id of
> second image
> $temp=$data->{property}->[0]->{images}->[0]->{image}->[0]{content}; #
> Property Image of first image
> $temp=$data->{property}->[0]->{images}->[0]->{image}->[1]{content}; #
> Property Image of second image
>
> Regards
> John


Hi John
Unfortunately this didn't work for me, the output was blank.
zzapper
 
Reply With Quote
 
Jim Gibson
Guest
Posts: n/a
 
      06-18-2008
In article
<(E-Mail Removed)>,
zzapper <(E-Mail Removed)> wrote:

> On Jun 18, 1:39*pm, "John" <(E-Mail Removed)> wrote:
> > "zzapper" <(E-Mail Removed)> wrote in message
> >
> > news:(E-Mail Removed)...
> >
> >
> >
> > > 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->{property}->{554674}->{ac}[0];

> >
> > > Desperate!!
> > > zzapper

> >
> > Hi
> >
> > With ForceArray turned on.
> >
> > my $temp=$data->{property}->[0]->{images}->[0]->{image}->[0]{id}; # id of
> > first image
> > $temp=$data->{property}->[0]->{images}->[0]->{image}->[1]{id}; # id of
> > second image
> > $temp=$data->{property}->[0]->{images}->[0]->{image}->[0]{content}; #
> > Property Image of first image
> > $temp=$data->{property}->[0]->{images}->[0]->{image}->[1]{content}; #
> > Property Image of second image
> >
> > Regards
> > John

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


Try:

$data->{property}->{'55467'}->{images}->[0]->{image}->{'545'}->{content}

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

print Dumper(\$data);

--
Jim Gibson
 
Reply With Quote
 
zzapper
Guest
Posts: n/a
 
      06-18-2008
On Jun 18, 8:33*pm, Jim Gibson <(E-Mail Removed)> wrote:
> In article
> <(E-Mail Removed)>,
>
>
>
> zzapper <(E-Mail Removed)> wrote:
> > On Jun 18, 1:39*pm, "John" <(E-Mail Removed)> wrote:
> > > "zzapper" <(E-Mail Removed)> wrote in message

>
> > >news:(E-Mail Removed)....

>
> > > > 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->{property}->{554674}->{ac}[0];

>
> > > > Desperate!!
> > > > zzapper

>
> > > Hi

>
> > > With ForceArray turned on.

>
> > > my $temp=$data->{property}->[0]->{images}->[0]->{image}->[0]{id}; #id of
> > > first image
> > > $temp=$data->{property}->[0]->{images}->[0]->{image}->[1]{id}; # idof
> > > second image
> > > $temp=$data->{property}->[0]->{images}->[0]->{image}->[0]{content};#
> > > Property Image of first image
> > > $temp=$data->{property}->[0]->{images}->[0]->{image}->[1]{content};#
> > > Property Image of second image

>
> > > Regards
> > > John

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

>
> Try:
>
> $data->{property}->{'55467'}->{images}->[0]->{image}->{'545'}->{content}
>
> To figure these things out, use the Data:umper 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 = $xml->XMLin("prop.xml", KeyAttr => {images => 'image'});
Which works if don't use forcearray.

gives me

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


zzapper
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
wsdl2java: method parameter a complex type that extends another complex type Robert Mark Bram Java 0 02-04-2007 10:06 AM
[XML Schema] Content type of complex type definition with complex content Stanimir Stamenkov XML 2 10-25-2005 10:16 AM
Problem accessing complex XML child node when using Dataset N. Demos ASP .Net 0 06-09-2005 01:45 PM
For expert on complex loops (reposted) - complex looping problem news.amnet.net.au Java 1 04-13-2004 07:10 AM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM



Advertisments