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


In reply to Browser choking on XML-header by schumi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.