Hi
horrendo,
I haven't done anything with XML before, but my recent work project will require it, so I used your question to "get my feet wet".
Take a look at the XML::Simple documentation (hint: search for
"xml version="), and you'll find:
XMLDecl => 1 or XMLDecl => 'string' *# out - handy*
If you want the output from "XMLout()" to start with the optional
+XML
declaration, simply set the option to '1'. The default XML declara
+tion
is:
<?xml version='1.0' standalone='yes'?>
If you want some other string (for example to declare an encoding
value), set the value of this option to the complete string you re
+quire.
That (plus the first couple of lines of the SYNOPSIS) quickly let me arrive at the following code sample, all within a few minutes:
use strict;
use warnings;
use XML::Simple;
my $h_ref = {
'a' => 1,
'b' => 2,
'c' => 3,
'colors' => [ 'red', 'green', 'blue' ],
'sub_hash' => {
'numbers' => [ 0, 1, 2],
'letters' => {
'vowels' => [qw[a e i o u]],
},
},
};
my $ref = "1,2,3";
my $xs = XML::Simple->new(ForceArray => 1, KeepRoot => 1, XMLDecl =>
+1);
my $xml = $xs->XMLout($h_ref);
print "XML is:\n$xml\n";
__END__
[Output]
<?xml version='1.0' standalone='yes'?>
<opt a="1" b="2" c="3">
<colors>red</colors>
<colors>green</colors>
<colors>blue</colors>
<sub_hash>
<letters>
<vowels>a</vowels>
<vowels>e</vowels>
<vowels>i</vowels>
<vowels>o</vowels>
<vowels>u</vowels>
</letters>
<numbers>0</numbers>
<numbers>1</numbers>
<numbers>2</numbers>
</sub_hash>
</opt>
Update: Made search string more specific.
s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/