
Originally Posted by
scrapmetalca
<meta http-equiv="Content-Type" content="application/xml; charset=ISO-8859-1" />
Is that the right thing to add.
What Twey said: no. As I wrote in my post, you need to use the PHP header function. Headers are part of the HTTP protocol, sent before the content generated by your code[1]. You need to include:
Code:
header('Content-Type: application/xml');
You can add a character encoding (charset) parameter, though you might want to consider UTF-8 (the default for both XML and XMLHttpRequest) over ISO-8859-1. Either way, make sure that the parameter is accurate.
As Twey also mentioned, meta elements containing content type hints are ignored in XML. Indeed, the only things that will care about these even in HTML are browsers, yet they are not the only interested parties. The Web is built on top of the Internet, and you, the developer, have no idea what lies between your server and your visitors. Caching servers and gateways may be very interested in this sort of metadata, which is why it should be the server that sets it.
If you aren't familiar with HTTP, and you intend to work with server-side languages, then, in my opinion, you really should become aquainted the protocol. The specification (RFC 2616) is quite readable, and you can probably find other primers on the Web to help you along (though 2616 really is mandatory reading, in the end).
Mike
[1] Hence the header function needs to be called before your code starts writing data to the output stream (unless output buffering is used). If the header function is called later, a warning will be generated.
Bookmarks