Can't get 'content' element to fold correctly in XML::Simple
by Mark Knoop other posts by this author
May 6 2009 6:12AM messages near this date
view in the new Beta List Site
RE: Parsing empty fields XML using perl
|
Re: Can't get 'content' element to fold correctly in XML::Simple
& XSLT Hi
Take the following xml
<?xml version="1.0" encoding="UTF-8" ?>
<data>
<content>
<id> 1</id>
<info> someinfo</info>
</content>
<content>
<id> 2</id>
<info> somemoreinfo</info>
</content>
</data>
If I XMLin it with no options it becomes (using Data::Dumper)
$VAR1 = {
'content' => {
'1' => {
'info' => 'someinfo'
},
'2' => {
'info' => 'somemoreinfo'
}
}
};
Which is what I want.
However if there is only one content tag eg
<?xml version="1.0" encoding="UTF-8" ?>
<data>
<content>
<id> 1</id>
<info> someinfo</info>
</content>
</data>
try as I might I just get
$VAR1 = {
'content' => {
'info' => 'someinfo',
'id' => '1'
}
};
whereas what I really want is
$VAR1 = {
'content' => {
'1' => {
'info' => 'someinfo',
}
}
};
I have tried using options such as
my $xml_ref = XMLin('singleton.xml',
ForceArray => ['content'],
KeyAttr => ['id']
);
or even
my $xml_ref = XMLin('singleton.xml',
KeyAttr => {content=>'id'},
ForceArray => ['content'],
);
but still I can't get it to fold on content => id
I am guessing it is something weird to do with 'content' as when I change
the element name to something else
<?xml version="1.0" encoding="UTF-8" ?>
<data>
<test>
<id> 1</id>
<info> someinfo</info>
</test>
</data>
and use the following options
my $xml_ref = XMLin('singleton.xml',
KeyAttr => {test=>'id'},
ForceArray => ['test'],
);
I get
$VAR1 = {
'test' => {
'1' => {
'info' => 'someinfo'
}
}
};
which IS what I want.
Is there a workaround with the 'content' element (other than getting the XML
provider to change their spec)?
Thanks
Mark
_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Mark Knoop
Jenda Krynicky
|