vinoth.ree has asked for the wisdom of the Perl Monks concerning the following question:
I stared to learn XML::Writer and XML::Reader
use XML::Writer; use XML::Reader; use IO::File; open(FH,"./input.txt"); #open the input file my $input; my $output = new IO::File(">converted_to_xml.xml"); #file to write the + converted content my $writer = new XML::Writer(OUTPUT => $output); #write into the opene +d file my @array=qw(name emp_no designation salary); while($input=<FH>){ #Read the input line from the file chomp($input); #remove the newline character my($name,$emp_no,$designation,$salary)=split /:/, $input; #split t +he input by comma character $writer->xmlDecl("UTF-8"); #XML declaration foreach my $val(@array){ $writer->startTag("$val"); #Starting tag my $var="\$".$val; $writer->characters(eval("$var")); #Character data in an XM +L document $writer->endTag("$val"); } } $writer->end(); $output->close();
In this above code I was using the XML::Writer to generate the XML file like below for each employee.
<name>XXXX</name> <emp_no>XXXX<emp_no> <designation>XXX<designation> <salary>XXXX<salary>
When I execute the above code it says error message,
Attempt to insert start tag after close of document element at Write_to_XML.pl line 47
If I use the endTag after the foreach loop I won't get XML file with all employee, I get only first employee details in the XML file.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Writer error message
by pKai (Priest) on Jul 07, 2009 at 07:37 UTC | |
|
Re: XML::Writer error message
by Anonymous Monk on Jul 07, 2009 at 06:32 UTC | |
by pKai (Priest) on Jul 07, 2009 at 09:51 UTC | |
by Anonymous Monk on Jul 07, 2009 at 10:10 UTC | |
by vinoth.ree (Monsignor) on Jul 08, 2009 at 03:59 UTC |