|
Posted by Tim Hunt on 08/04/06 03:38
runner7 wrote:
> This is a question about outputting pure XML from PHP, such as to a
> request object in an AJAX application. I would suppose that all I have
> to do in my script is to add the line before any other output:
>
> header('Content-Type: text/xml');
>
> Then I should be able to use the ordinary output mechanisms of literals
> outside of php tags, and "echo" and "print" inside php tags.
>
> This post is not about the caching issues which I am aware of. Can
> anyone tell me if all this is correct and if the following assumptions
> are correct?
>
> 1. This header will replace the "Content-Type" header sent by the web
> server.
>
> 2. I do not need to specify a character set in the header, or do I?
Hi
For everything except the character set question the answer is yes.
The charset is optional, it should work without setting a charset but
its recommended (by the w3c in particular). I'd only leave the charset
out if it was personal use only, my own habit - others may disagree.
It may be worth noting the default charset for text/xml is "us-ascii" (
http://www.zvon.org/tmRFC/RFC3023/Output/chapter3.html#sub1 , para 3)
The default charset for text/xml differs from the default iso-8859
charset for "text/..." content-types
(http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1)
And if you set a charset in header() it overrides a charset defined
with <?xml encoding="???">
Regards,
Tim Hunt
Navigation:
[Reply to this message]
|