views:

383

answers:

2

I am just trying to create the XML

use XML::Simple;

my %element = ( "a" => "10" , 
                "b" => "20" ,);

my $xs = new XML::Simple();
my $ref = $xs->XMLin(%element);
my $xml = $xs->XMLout($ref);
print $xml;

What is wrong on this code ? ( This is got Resolved )

use XML::Simple;

my %element = ( "a" => "10" , 
                "b" => "20" ,);

my $xs = new XML::Simple();
my $xml = $xs->XMLout(\%element);
print $xml;

This produces the following output:

<opt a="10" b="20" />

But what I'd really like to get is this:

<a> 10 </a>
<b> 20 </b>

How can I achieve this?

+2  A: 

You're using it backwards. XMLin is an XML decoder (takes an XML-encoded document, returns Perl structures); XMLout is an XML encoder (takes Perl structures, returns an XML-encoded document).

JB
Either way i am not able to acheive what i want . I just want to create the XML element based on Hash array
joe
+3  A: 

XMLin takes XML and transforms it into a Perl data structure.

XMLout takes a Perl data strcuture and transforms it to XML.

You are trying to feed a Perl data structure to XMLin and feed the result to XMLout.

Have you considered reading the documentation?


Update: The documentation (yes, we know it's boring) offers quite a lot of options that you can pass to XML::Simple::new(). One of them is NoAttr => 1. You might want to check that one out, but a look at the others (some of which are marked "important") won't hurt.

innaM