1

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?

Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
joe
  • 34,529
  • 29
  • 100
  • 137

2 Answers2

4

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
  • 47,505
  • 4
  • 67
  • 87
2

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.
  • 40,344
  • 12
  • 79
  • 106
  • Either way i am not able to acheive what i want . I just want to create the XML element based on Hash array – joe Jun 25 '09 at 09:25