Thank You for your replies monks, I was getting the hash as an input from a file with incorrect structuring. Anyways, the structure was corrected and I am now getting the Hash structure as
$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' } } },
Using XML::Simple, I was able to convert it to basic XML as follows
<?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>
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> <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>
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?

In reply to Perl and XML by Bugz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.