Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: XML module which one

by 7stud (Deacon)
on Feb 05, 2013 at 03:56 UTC ( #1017051=note: print w/ replies, xml ) Need Help??


in reply to XML module which one

XML::Simple can do it:

use strict; use warnings; use 5.012; use XML::Simple; my %form_data = ( name => 'Joe', weight => 180, ); my $xml_obj = XML::Simple->new(RootName => 'form1'); say $xml_obj->XMLout( \%form_data, noattr => 1, xmldecl => q{<?xml version="1.0">}, ); --output:-- <?xml version="1.0"> <form1> <name>Joe</name> <weight>180</weight> </form1>


Comment on Re: XML module which one
Download Code
Re^2: XML module which one
by spencerr1 (Novice) on Feb 05, 2013 at 04:15 UTC

    I was thinking about using XML::Simple because it looks simple enough but when I get data from the form (many name = value results it looks like I would have to manually enter them in another script right? I was hopping to have a script that opened up the cgi.pm form results and could draw the key = value results in an XML document.

      ...but when I get data from the form (many name = value results it looks like I would have to manually enter them in another script right? I was hopping to have a script that opened up the cgi.pm form results and could draw the key = value results in an XML document.

      What do you mean 'another script'? Even if you had to retrieve each name/value pair one by one and insert them in a hash, then feed the hash to XML::Simple to create the xml, you would do it all in the same script. Moreover, you do not have to retrieve the form data one name/value at a time--because the cgi module makes the form data available to you as a hash. See the section titled FETCHING THE PARAMETER LIST AS A HASH in the cgi docs. Then you can pass that hash as an argument to XMLout() to produce the xml.

        I wouldn't recommend XML::Simple and CGI->Vars to anyone, especially newbies, too many caveats

        O.K. I will try that. Now I'm starting to see the light

        Thanks for helping me out I will give it a go

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2014-09-19 21:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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











    Results (146 votes), past polls