mailmeakhila has asked for the wisdom of the Perl Monks concerning the following question:

Hi My HTML is :
<html><head><title>Report</title></head> <body> <form action="http://localhost/cgi-bin/temp.txt" method="POST"> <br> Text Box: <br> <input type="text" name="sample_text"> <br> <br> Check Box: <br> <input type="checkbox" name="red" value=1>Red<br> <br> <input type="checkbox" name="blue" value=1>Blue<br> <br> Radio Button <br> <input type="radio" name="Boolean" value="true">True<br> <br> <input type="radio" name="Boolean" value="false">False<br> <br> <input type = "submit" name = "submit" value = "submit"/> </form> </body></html>
The cgi script is
#! /usr/bin/perl -w print "Content-type: text/html\n\n"; use CGI; use IO::File; use XML::Simple; my %form; my $cgi = CGI->new; foreach my $field ($cgi->param()) { $form{$field} = $cgi->param($field); } my $hash_ref = \%form; my $output = new IO::File(">out.xml"); my $xml = XML::Simple::XMLout($hash_ref, OutputFile => $output); $output->close();
The output that i am getting is
<opt Boolean="true" blue="1" red="1" sample_text="ak" submit="submit"/ +>
This is how i want it to look like: <code> <opt> <boolean>true</boolean> <blue>1</blue> <red>1</red> <sample_text>ak</sample_text> <submit>submit</submit> </opt> Can anyone help to get the output i want.

Replies are listed 'Best First'.
Re: Formatting XML to tree
by ww (Archbishop) on Nov 10, 2011 at 22:53 UTC

    Ignore (unless the parent loses content again). OP (?) appears to have restored the missing content.

    Removed from the parent node (possibly in an editing error by OP):

    "My Cgi script to convert to XML is

    #! /usr/bin/perl -w print "Content-type: text/html\n\n"; use CGI; use IO::File; use XML::Simple; my %form; my $cgi = CGI->new; foreach my $field ($cgi->param()) { $form{$field} = $cgi->param($field); } my $hash_ref = \%form; my $output = new IO::File(">out.xml"); my $xml = XML::Simple::XMLout($hash_ref, OutputFile => $output); $output->close();

    My HTML Document is

    <html><head><title>Report</title></head> <body> <form action="http://localhost/cgi-bin/Exmp.cgi" method="POST"> <br> Text Box: <br> <input type="text" name="sample_text"> <br> <br> Check Box: <br> <input type="checkbox" name="red" value=1>Red<br> <br> <input type="checkbox" name="blue" value=1>Blue<br> <br> Radio Button <br> <input type="radio" name="Boolean" value="true">True<br> <br> <input type="radio" name="Boolean" value="false">False<br> <br> <input type = "submit" name = "submit" value = "submit"/> </form> </body></html>

    Can anyone help

    </end restoration>

    At least when I saw it first, desired output already existed... and AM's Re: Formatting XML to tree was (not visible | not yet extant)

Re: Formatting XML to tree
by Anonymous Monk on Nov 10, 2011 at 22:16 UTC