arcnon has asked for the wisdom of the Perl Monks concerning the following question:

I have been fiddling with this trying to get XML::Simple to produce the correct xml file. I have a application written. I have decided that I would take my data structures and convert them to xml. I have taken the hash structure and tried to convert it.
my %t_type = ( ... 'b' => { a => {low => 1000, high => 3000, percent => 25}, b => {low => 200,high => 2000, percent => 30}, c => {low => 1000,high => 6000, percent => 40}, d => {low => 300,high => 1800, percent => 35}, e => {low => 10, high => 40, percent => 60}, f => {low => 2, high => 12, percent => 50}, g => [ {select => 'new',low => 1,high => 1,percent => 10}, {select => 'expert',low => 1,high => 1,percent => 10}, ], }, ... );
note: the g hash of arrays has at least 1 element but can be more. In the current xml file output. It creates mutiple g's with 1 entry per g array item. Which when read back in produces a differant struture. This is the options I am using to produce the file.
print L $xsimple->XMLout( \%t_type, noattr => 1, xmldecl => '<?xml version="1.0"?>', );
I tried the GroupTags => { '' => 'g' } and GroupTags => { 'g' => 'select' } but with no success. any suggestions, solutions. thanks

Replies are listed 'Best First'.
Re: hash XML rounding trip
by dragonchild (Archbishop) on Aug 27, 2004 at 13:38 UTC
    Try GroupTags => { g => 'element' } and see if that helps. Also, what does with no success mean? How was the second attempt (which is very similar to my suggestion) not successful? What didn't it do that you thought it should?

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

      GroupTags => { '' => 'g' } this produced 2 'g' records with 1 array item in each
      GroupTags => { 'g' => 'select' } <g> <select> <high>3</high> <low>3</low> <percent>30</percent> <select>any</select> </select> </g>
        First off, it's really helpful if you provide output that correlates to your input. Otherwise, I can't see if there's anything wrong. Remember - I have absolutely no information save for what you give me. If that information comes from two sources, I can't make heads or tails of it.

        Second - I would try the second option with more than one element in the array and see what the XML looks like. I suspect that it will be doing what you want it to do.

        ------
        We are the carpenters and bricklayers of the Information Age.

        Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

        I shouldn't have to say this, but any code, unless otherwise stated, is untested

Re: hash XML rounding trip
by arcnon (Monk) on Aug 27, 2004 at 14:28 UTC
    that was it thanks. it produces
    <g> <element> <high>1</high> <percent>10</percent> <low>1</low> <select>armor</select> </element> <element> <high>1</high> <percent>10</percent> <low>1</low> <select>weapon</select> </element> </g>
    now to test the reading back into the structure.
      you say that it is almost the same but it produces total differant code. the above correct code(yours) and the 'g' => 'select' (mine) which created
      <g> <select> <high>3</high> <low>3</low> <percent>30</percent> <select>any</select> </select> </g>
      from the shown hash. Where g contains 2 array items. Why do you say they are the almost same? when they output so radically differant? I dont understand.
        The XML::Simple documentation suggests that you shouldn't use a childnode name as the name for the array elements. I suspect that may have something to do with it.

        ------
        We are the carpenters and bricklayers of the Information Age.

        Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

        I shouldn't have to say this, but any code, unless otherwise stated, is untested