Using XML::Simple, I was able to convert it to basic XML as follows$FIELDS = { 'AA' => { 'Description' => '', 'Type' => 'Module', 'File' => 'Sample1.pl', }, 'BB' => { 'Description' => 'Initiator', 'Type' => 'Methods', 'File' => 'Sample1.pl', }, 'CC' => { 'Description' => 'Destructor', 'Type' => 'Methods', 'File' => 'Sample2.pl', 'Values' => { '1' => 'Ignore', '2' => 'Retry', '3' => 'Abort' } } },
As you can see the XML tags <1> <2> <3> would be illegal, so I want to convert the data to something like following:<?xml version = "1.0"?> <data> <AA> <Description></Description> <Type>Module</Type> <File>Sample1.pl</File> </AA> <BB> <Description>Initiator</Description> <Type>Methods</Type> <File>Sample1.pl</File> </BB> <CC> <Description>Destructor</Description> <Type>Methods</Type> <File>Sample2.pl</File> <Value> <1>Ignore</1> <2>Retry</2> <3>Abort</3> </Value> </C> </data>
The idea to introduce numbers with nodes, was to ensure, two nodes with same name can exist. I am unsure of how XML::Writer or XML::Twig could be able to parse the Perl Hash into the XML structure I need. Any Suggestions please?<?xml version = "1.0"?> <data> <Node No='1' Label='AA'> <Description></Description> <Type>Module</Type> <File>Sample1.pl</File> </Node> <Node No= '2' Label='BB'> <Description>Initiator</Description> <Type>Methods</Type> <File>Sample1.pl</File> </Node> <Node No='3' Label='CC'> <Description>Destructor</Description> <Type>Methods</Type> <File>Sample2.pl</File> <Value No='1'>Ignore</Value> <Value No='2'>Retry</Value> <Value No='3'>Abort</Value> </Node> </data>
In reply to Perl and XML by Bugz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |