PV66 has asked for the wisdom of the Perl Monks concerning the following question:
Basically I have an XML
I want to get the ref name's value, that is "abc_sia_%version1.ref%" as my hash key and the corresponding elements of the tag in a list. So I used Simple XML's function<root> <ref name="abc_sia_%version1.ref%"> <func envname = "test01" objectdir = "/home/pv66" base="default_771"/> </ref> </root>
But this gives memy $xml = new XML::Simple; my $data = $xml->XMLin("/home/pv66", ForceArray => 1, KeyAttr => { ref + => "name"}); print Dumper ($data);
And this extra level of hierarchy (after ref) is undesired. I've read at some places that XML::Simple is not the preferred module, and XMLLib should be used, but I couldn't find any resources that drew a parallel to the ForceArray attribute of the XML in method. The desired hash should be:$VAR1 = { 'ref' => { 'abc_sia_%version1.ref' => { 'func' => [ { 'envname' => 'test01', 'objectdir' => '/home/pv66', 'base' => 'default_771' } ] } };
Any help pertaining to this would be appreciated.$VAR1 = { 'abc_sia_%version1.ref' => { 'func' => [ { 'envname' => 'test01', 'objectdir' => '/home/pv66', 'base' => 'default_771' } ] } };
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How do I get a list in a perl hash generated from an XML?
by choroba (Cardinal) on Apr 19, 2021 at 09:53 UTC | |
by PV66 (Novice) on Apr 19, 2021 at 12:19 UTC | |
by choroba (Cardinal) on Apr 20, 2021 at 11:46 UTC | |
| |
Re: How do I get a list in a perl hash generated from an XML?
by AnomalousMonk (Archbishop) on Apr 19, 2021 at 09:15 UTC | |
by PV66 (Novice) on Apr 19, 2021 at 09:46 UTC | |
Re: How do I get a list in a perl hash generated from an XML?
by haukex (Archbishop) on Apr 20, 2021 at 05:56 UTC | |
A reply falls below the community's threshold of quality. You may see it by logging in. |