|
-
Dec 3rd, 2003, 05:57 AM
#1
Thread Starter
Addicted Member
XML / Perl: Perl CGI script returning XML
I'm trying to make a perl script that returns XML instead of HTML.
my script currently looks like this...
Code:
#!/usr/bin/perl
#
#print xml info
print "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
print "<programlist>\n";
print "</programlist>\n";
which creates the following xml file
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<programlist>
</programlist>
this works fine if i save the output to a file and view it in a browser however if i run the perl script in my browser I get a "500 Internal Server Error".
Looking at the apache error log i get
Code:
malformed header from script. Bad header=<?xml version="1.0" encoding=": /usr/local/apache/cgi-bin/getChannels.pl
does anyone know how to stop this???
Thanks for your help
Mrs K
Ford? Theres an infinite number of monkeys outside that want to talk to you about a script of hamlet they've produced!
-
Dec 3rd, 2003, 01:04 PM
#2
Member
You need to print out an HTTP Content-Type header before your content. For HTML it would be
Code:
print "Content-Type: text/html\n\n";
I would assume that XML is
Code:
print "Content-Type: text/xml\n\n";
but I'm not certain.
-
Dec 7th, 2003, 04:48 PM
#3
XML has two main MIME types: text/xml and application/xml. I'm not sure which is to be used for which, but I think text/xml is for XML files that are pure data, while application/xml is for XML languages that actually instruct an app to do something.
Example for text/xml:
Code:
<storelist>
<item>
<name>Chair</name>
<amount>32</amount>
</item>
<item>
<name>Table</name>
<amount>5</amount>
</item>
</storelist>
Examples for application/xml are XHTML and SVG. Those have their own MIME types though: XHTML uses application/xhtml+xml and SVG uses image/svg+xml.
I'm sure this is explained in greater detail in the XML specification.
www.w3.org
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 7th, 2003, 05:01 PM
#4
Here's the IETF RFC that explains them.
http://www.ietf.org/rfc/rfc2376.txt
This document also has some stuff to say about the default handling of text/* types. For practical considerations, if you use text/xml, you MUST either use us-ascii as character set or specify the encoding explicitly, as in
print "Content-Type: text/xml; charset=\"UTF-16\"\n\n";
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|