Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: XML::Simple, XMLout and encoding

by liverpole (Monsignor)
on Mar 02, 2010 at 00:15 UTC ( #826031=note: print w/ replies, xml ) Need Help??


in reply to XML::Simple, XMLout and encoding

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


Comment on Re: XML::Simple, XMLout and encoding
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2014-09-17 10:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (72 votes), past polls