[Israel.pm] returning XML from CGI

Yuval Yaari yuval at windax.com
Mon Sep 20 23:19:19 PDT 2004

> Hello,
> I have a CGI script that accepts some parameters from a form
> and is supposed to return an XML document.
> I'm able to return an HTML with the XML document inlined
> (after some entity manipulation: mainly transforming < to
> &lt; and > to &gt;), but I don't seem to be able to return
> an XML document as the HTTP response in a way that is
> recognized by the browser as an XML file.
> This:
>  print header(-type=>'text/xml', charset=>'UTF-8');
>  print $xml_document
> should have done the trick but all the browser shows me is a
> blank page. The only way to view the actual document that
> was returned is by viewing the page source.
> Is there something that I'm missing here?

This might be a stupid question, but does $xml_document store valid XML 
(i.e: the browser should show it correctly)?
What if you print your own HTTP header instead of letting CGI do it?
What if you, say, put it in a file, download the file, and open it in your 
Ok, it does sound stupid, but I'm just trying to weed out HTTP header 
problems, since you say that viewing the source shows you the page.

The header looks fine to me, but that doesn't mean a lot :)


More information about the Perl mailing list