More on my XML/RSS feeds not rendering Jun06 '05
To follow up with my XML rendering problem, I did some more research on Content-Type headers, Apache, PHP, and XML.
Content–Type and headers
I discovered that, by default, PHP pages (.php) are displayed as text/html.
When I say "displayed as...," I am referring to what the browser interprets the page to be. In other words, if the browser sees a header of text/html, it knows to expect HTML code, and it renders the page appropriately.
An XML file (.xml) must be displayed as either text/xml, application/xml, application/xhtml+xml, or a few others I can’t recall right now.
Apache AddType
My problem is that requests (on my server) for XML/RSS files are treated as PHP – because if they weren’t, I wouldn’t be able to dynamically gather their content. And that would make the RSS files useless.
The code that treats XML files as PHP is this:
AddType php-cgi .xml
This is certainly a small code addition, for such a valuable commodity.
However, it presents a slight "catch 22."
In order to utilize dynamic content, my XML file must be treated as PHP. But... in order for the browser to render the XML correctly, it must be treated as XML.
Possible solution
Despite the fact that my XML files are being treated as PHP (via Apache AddType) - they can still be rendered as XML, by specifying the appropriate Content–Type, or header.
This is done by using the PHP header() function:
<?php header('Content-type: text/xml'); ?>
If this call is specified before any other output, your XML file (although treated as PHP), will still render as XML.
You’ll possibly hear more from me
I am still working out some "kinks," with my own CMS, so I have yet to get this working properly.
Hopefully, I will soon.
If not, you know you’ll hear more from me, on this subject!
Categories: Apache
, PHP
, RSS ![]()
Add Feedback (view all)
Leave feedback
matthom
is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from Chicago.
Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.
Similar Entries
- RSS Best Practices? (4 recent visits)
- What are your RSS opinions? (2 recent visits)
- New RSS feed – Bulls game alerts (1 recent visits)
- Filtered Lifehacker RSS feed using Yahoo! Pipes (54 recent visits)
- Web site stats via email or RSS (6 recent visits)
- Digg will eventually replace my RSS subscriptions (5 recent visits)
Stats
93 unique visits since August 2008
Recent Referrers (click)
- php render xml
- apache php not rendering
- yahoo pipes rss render not working
- dynamically render xml
- php code render rss feed
- xml pages not rendering
- rss addtype
- xml files are being treated as php
- addtype rss
- dynamic php rss feed render XML
- apache php page rendering as text file header issue
- addtype text/xml
- rss not rendering in ie
- rendering rss feed in php
- AddType .rss
- yahoo pipes render php
- php render xml
- yahoo pipes render
- php header for yahoo rss
- addtype xml file as php