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$..$/

In reply to Re: XML::Simple, XMLout and encoding by liverpole
in thread XML::Simple, XMLout and encoding by horrendo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.