Hi, Having a problem with XML::Simple. In a nutshell if I try and output an xml file containing a node more that 3 levels deep XML::Simple stops producing the correct output and starts inserting "<name>" nodes. Not sure if some option or another stops the behaviour but somethings not right, (my intend use of XML::Simple is to simply output a hash produced by a sub() as an xml stream, use XMLin below just to test).

Here's a demo of the behaviour, I read in a xml file and would expect XMLout to replicate.

#Read in raw xml, where test.xml is: #<test><level1><level2><level3>testme</level3></level2></level1></test +> my $xs = new XML::Simple; my $ref = $xs->XMLin("test.xml"); #Use dumper to show the data structure created by XMLin print Dumper($ref); #Complete the circle and output the xml print $xs->XMLout($ref,NoAttr => 1,RootName=>'test');

The correct output would be a replica of test.xml, e.g.

<test> <level1> <level2> <level3>testme</level3> </level2> </level1> </test>

The actual output is XMLout:

<test> <level1> <name>level2</name> <level3>testme</level3> </level1> </test>

Would seem that despite the dumped data structure produced by XMLin being correct.

$VAR1 = { 'level1' => { 'level2' => { 'level3' => 'testme' } } }

'level3' is not wrapped within 'level2', instead the hashkey's value is embedded within a 'name' node? Can anybody suggest why?

Many thanks for any advice!


In reply to XML::Simple Error by duesouth

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.