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

I want to output a hash to xml. I'm using xml::simple, but the formatting is not quite what I would expect/desire". A dumper of the hash shows:
$VAR1 = { 'xfire' => { 'summary' => 1, 'config' => 1 } };
My code will output:
<qa_logs> <xfire config="1" summary="1" /> </qa_logs>
What I want is:
<qa_logs> <xfire> <config>1</config> <summary>1</summary> </xfire> </qa_logs>
Is there an easy way to do this? Do I need to build my hash differently? Thanks! (BTW: I also would like to append to a file rather than create a new one. I guess the best way to do this is to open the file to append, and then not specify OutputFile for XMLout). Code snippet:
XMLout(\%qa_logs, OutputFile => "newfile.xml", RootName => 'qa_logs');

Replies are listed 'Best First'.
Re: Help with output formatting with xml::simple
by NetWallah (Canon) on May 20, 2013 at 21:49 UTC
    Welcome to the Monastery , and please use <code> tags to show code, as explained in Writeup Formatting Tips.

    XML::Simple has the "NoAttr" option to produce the XML you want:

    >perl -E "use XML::Simple qw||;my $xs=XML::Simple::->new(NoAttr=>1);sa y $xs->XMLout ({x=>{Summ=>1,Config=>2}})" <opt> <x> <Config>2</Config> <Summ>1</Summ> </x> </opt>

                 "I'm fairly sure if they took porn off the Internet, there'd only be one website left, and it'd be called 'Bring Back the Porn!'"
            -- Dr. Cox, Scrubs