For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > January 2006 > Using XML::Simple









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Using XML::Simple
Bjorn Van Blanckenberg

2006-01-19, 3:57 am

I have some elements in my xml that are empty but have attributes.
I would like that I can group the element in function of Attribute Name.

<Layout Class="Parameter" ID="r060116_103344354_000026"
Status="Available">
<LayerList>
<LayerDetails Name="nl-BE"/>
<LayerDetails Name="fr-BE"/>
<LayerDetails Name="nl-NL"/>
</LayerList>
</Layout>

I read in I get

$VAR1 = {
'ID' => 'r060116_103344354_000026',
'Status' => 'Available',
'LayerList' => {
'LayerDetails' => [
{
'Name' => 'nl-BE'
},
{
'Name' => 'fr-BE'
},
{
'Name' => 'nl-NL'
}
]
},
'Class' => 'Parameter'
};


I would like it when the xml is readed in to became

{
'ID' => 'r060116_103344354_000026',
'Status' => 'Available',
'LayerList' => {
'LayerDetails' => [ 'nl-BE', 'fr-BE', 'nl-
NL' ]
},
'Class' => 'Parameter'
}
}

I've tried to use
# KeyAttr => [ list ]
# KeyAttr => { list }
# GroupTags => { grouping tag => grouped tag }

even an combination of KeyAttri and GroupTags but don't get the
desired output

Thanks Bjorn

John Doe

2006-01-19, 7:56 am

Bjorn Van Blanckenberg am Donnerstag, 19. Januar 2006 09.33:
> I have some elements in my xml that are empty but have attributes.
> I would like that I can group the element in function of Attribute Name.
>
> <Layout Class="Parameter" ID="r060116_103344354_000026"
> Status="Available">
> <LayerList>
> <LayerDetails Name="nl-BE"/>
> <LayerDetails Name="fr-BE"/>
> <LayerDetails Name="nl-NL"/>
> </LayerList>
> </Layout>
>
> I read in I get
>
> $VAR1 = {
> 'ID' => 'r060116_103344354_000026',
> 'Status' => 'Available',
> 'LayerList' => {
> 'LayerDetails' => [
> {
> 'Name' => 'nl-BE'
> },
> {
> 'Name' => 'fr-BE'
> },
> {
> 'Name' => 'nl-NL'
> }
> ]
> },
> 'Class' => 'Parameter'
> };
>
>
> I would like it when the xml is readed in to became
>
> {
> 'ID' => 'r060116_103344354_000026',
> 'Status' => 'Available',
> 'LayerList' => {
> 'LayerDetails' => [ 'nl-BE', 'fr-BE', 'nl-
> NL' ]
> },
> 'Class' => 'Parameter'
> }
> }
>
> I've tried to use
> # KeyAttr => [ list ]
> # KeyAttr => { list }
> # GroupTags => { grouping tag => grouped tag }
>
> even an combination of KeyAttri and GroupTags but don't get the
> desired output


Just in case it's not possible with XML::Simple, you could use a workaround on
the result data structure by transforming it with:

$VAR1->{LayerList}->{LayerDetails}=
[ map {%$_} @{$VAR1->{LayerList}->{LayerDetails}} ];

hth, joe

Bjorn Van Blanckenberg

2006-01-19, 6:58 pm

I had to use an combination of GroupTags and then ValueAttr

my $ref = XMLin($jdf,GroupTags => { LayerList => 'LayerDetails' },
ValueAttr => [ LayerList => 'Name' ] );

thanks

On 19-jan-06, at 12:43, John Doe wrote:

> Bjorn Van Blanckenberg am Donnerstag, 19. Januar 2006 09.33:
>
> Just in case it's not possible with XML::Simple, you could use a
> workaround on
> the result data structure by transforming it with:
>
> $VAR1->{LayerList}->{LayerDetails}=
> [ map {%$_} @{$VAR1->{LayerList}->{LayerDetails}} ];
>
> hth, joe
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>


RangerRickCA@aol.com

2006-01-19, 6:58 pm

Please remove me from this list! Thank you!

RRCA

RangerRickCA@aol.com

2006-01-19, 6:58 pm


Please remove me from this list! Thank you!

RRCA


Michael Coll-Barth

2006-01-19, 6:58 pm


Well, I just gave this email address to a SPAM list....


-----Original Message-----
From: RangerRickCA@aol.com [mailto:RangerRickCA@aol.com]
Sent: Thursday, January 19, 2006 12:59 PM
To: bjornvb@ppc.be; beginners@perl.org
Subject: Re: Using XML::Simple


Please remove me from this list! Thank you!
=20
RRCA


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com