Greetings, Fellow Monks!
I have a problem with XML, HTML and browsers. I'm trying to get a script write some data into an XML-file which should then be written to the disk, and once this is done, the browser should display a message.
Now, I have managed to cobble together a script as shown below, which works fine from the command line. But as soon as I run it from any browser, I get a 500 server error, and the error_log snickeringly displays the following:
malformed header from script. Bad header=<?xml version="1.0" encoding=
+": /home/httpd/cgi-bin/guestbook/test.pl
It seems to me that the server gets an XML header and thinks it's supposed to display that, even though the file should actually be written to the disk rather than be sent to the browser.
I'm stuck, and maybe it's something very obvious that I just can't see anymore after the last 9 hours of office. Can anyone help me there?
#!/usr/bin/perl -wT
use strict;
use CGI;
use IO;
use XML::Writer;
my $cgi = new CGI;
my $i;
my @data;
my $e = 0;
my $outfile = new IO::File(">test.xml");
my $writer = new XML::Writer(OUTPUT => $outfile, DATA_MODE => 'true',
+DATA_INDENT => 2, UNSAFE => 1);
$writer->xmlDecl('ISO-8859-1');
$writer->comment('Test-Entries');
$data[$e]{date} = "11-12-2002";
$data[$e]{nom} = "Fred Bloggs ";
$data[$e]{email} = 'fred@bloggs.ch';
$data[$e]{eintrag} = "This is a test!";
$writer->startTag('test');
for $i (0 .. $#data) {
$writer->startTag('entry');
foreach my $data (keys %{$data[$i]}) {
$writer->startTag($data);
$writer->characters($data[$i]{$data});
$writer->endTag();
}
$writer->endTag();
}
$writer->endTag();
$writer->end();
print $cgi->header;
print "Done!\n";
And yes, I realise that the structure $data[$e]{whatever} is peculiar. Has something to do with what the script is supposed to be part of later.
Anyway, thanks for trying to get your head around my problems, and have a nice localtime!
--cs
There are nights when the wolves are silent and only the moon howls. - George Carlin
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.