Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

[Solved] Very simple XML::Simple problem

by mascip (Pilgrim)
on Nov 07, 2012 at 15:59 UTC ( #1002687=perlquestion: print w/ replies, xml ) Need Help??
mascip has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,
I want to get rid of the <opt> node, created with XMLout().

Let me illustrate this. I want to create a piece of XML that looks like this :

<book_1>title_1</book1> <book_2>title_2</book1>
And with this piece of code :
use XML::Simple; my %xml_hash = ( book1 => ['bla'], book2 => ['bli'], ); my $xml = XMLout(\%xml_hash, KeyAttr => []); print $xml;
i get this XML structure instead :
<opt> <book_1>title_1</book1> <book_2>title_2</book1> </opt>
I don't want this <opt> node, is there any way to not create it, with XMLout()?

Comment on [Solved] Very simple XML::Simple problem
Select or Download Code
Re: Very simple XML::Simple problem
by jacaril (Beadle) on Nov 07, 2012 at 16:25 UTC

    opts is the default root name, setting RootName to undefined should solve your issue.

    my $xml = XMLout(\%xml_hash,  RootName   => undef);
Re: Very simple XML::Simple problem
by roboticus (Canon) on Nov 07, 2012 at 16:31 UTC

    mascip:

    The docs for XML::Simple mention that you can control the root element with the RootName option. Setting it to undef or the empty string should make it leave off the root elements. Using another value should change the name "opt" to the specified name.

    Caveat: I've not played with it, I'm just spouting off info from the docs.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      I skipped this part of the doc apparently. Thanks a lot to you two !

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1002687]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2014-09-03 05:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls