Actually XML::Simple has a very simple rule for determining whether to output something as an attribute vs a nested element. If the value is a plain scalar, it will be output as an element, otherwise it will be a nested element.
Indeed... Just FYI, a co-worker and myself were evaluating XML::Simple for producing XML and he had the impression that there was no way to do this. If you glance at the SYNOPSIS, and see this:
'gobi' => { 'osversion' => '6.5', 'osname' => 'irix', 'address' => '10.0.0.102' },
you get the idea that there is no way to force address to be an element somehow.

I knew about ForceArray but for some reason, things didn't click for me until your post here.

regexps as "non-plain scalars"

I wanted to ease my typing. The standard "non-plain scalar" is this:
mother => ['Mary']
but I was hoping to get away with this:
mother => qr/Mary/
because it is easier to type and more readable (IMHO).

Any chance of converting a node whose value is a regexp into an element as opposed to an attribute?

Order of sibling XML elements

Now, one other question, we are producing XML based on an XSD. I am wondering if the XML has order requirements on siblings. In other words, I did the sample XML for the original topic in this thread in XML::Simple -
use strict; use warnings; use XML::Simple; use Tie::IxHash; tie (my %struct, 'Tie::IxHash', family => { name => 'Kawasaki', father => ['Yasuhisa'], mother => ['Chizuko'], children => { girl => ['Shiori'], boy => ['Kairi'], } } ); warn XMLout(\%struct);
but while each level of the XML tree was accurate, the sibling elements father, mother, children were in a different order than I wanted them to be.

In reply to XML::Simple - attribute encoding, order of XML by metaperl
in thread A data structure for XML generation by metaperl

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.