Menu
Ok, so I’m de-Dreamweavering the Dojo web site and along the way I’m adding an RSS feed. And I’d like tro provide the RSS file with an XSLT stylesheet so it is viewable on a browser as a part of the web site. Easy enough, except that I can’t seem to get it to work in Firefox. I think that it’s the external entities in the XSL. I’d like to do the stylesheet in PHP but how do I send an “application/xml” content type in the response header?
[code=php]header('Content-type: application/xml');
// rest of parsing commands[/code]
Error loading stylesheet:Is it possible that it is choking on the XML declaration?
An XSLT stylesheet does not have an XML mimetype:http://www.baltimoreaikido.com/rss.xsl.php [/quote]
[code=php]<?php
header('Content-Type: application/xml');
// ...
?>[/code]
you're using php to generate the xsl template?That's exactly what I'm doing, but I get an error on line 2. The prolog of my XSL file is something like:
you will need to send a header for that as well[code=php]<?php
[/QUOTE]
header('Content-Type: application/xml');
// ...
?>[/code]
<?php header('Content-Type: application/xml'); ?>
<?xml version="1.0" encoding="iso-8859-1"?>
<?php header('Content-Type: application/xml'); ?>How can someone with over 7000 posts call themselfs a noob? Ok, here's the problem. the PHP engine see this: [B]<?xml [/B] as a PHP short tag. Easiest way around this is to echo it with PHP.
<?xml version="1.0" encoding="iso-8859-1"?>[/code][/QUOTE]
[code=php]<?php echo '<?xml version="1.0" encoding="iso-8859-1"?>'; ?>[/code]
How can someone with over 7000 posts call themselfs a noob?[/QUOTE]I've been studying my martial art for seven years or so and have achieved the rank on sankyu. In five more I [i]might[/i] be promoted to the rank of shodan. "Shodan" translates as "beginner".
I just wish that there was a more elegant solution.[/QUOTE]Well I am guessing what you are doing... but... one option is to have your file containing no PHP but prepend a php file to it in htaccess. If this would be good for your project I will post how to do it. This could for example be done to all files of a certain type (css, xml, etc).
Well I am guessing what you are doing... but... one option is to have your file containing no PHP but prepend a php file to it in htaccess. If this would be good for your project I will post how to do it. This could for example be done to all files of a certain type (css, xml, etc).[/QUOTE]I need some PHP scattered about the file to replace the external entities. At least I think that I do. Thanks for the offer, but I think I'll learn to live with it. Thanks.
erver-side scripting is hardly ever "elegant" looking.[/QUOTE]It is when you are using Perl
server-side scripting is hardly ever "elegant" looking.[/QUOTE]That's all down to who is writing the script.
Well I am guessing what you are doing... but... one option is to have your file containing no PHP but prepend a php file to it in htaccess. If this would be good for your project I will post how to do it. This could for example be done to all files of a certain type (css, xml, etc).[/QUOTE]It looks like I'm going to need that prepending after all. It seems that neither my RSS reader nor my browser are picking up when I update the feed. Methinks I need an expiration date in the headers.
It looks like I'm going to need that prepending after all.[/QUOTE]Well I'll post that if you want it but I don't think that is the problem. Any file with a .php should be tested by the browser for a newer version but maybe your browser is caching the page. Have a look at
[code=php]<?xml version="1.0" encoding="iso-8859-1"?>[/code]
and replace it with: [code=php]<?php
header('Content-Type: application/xml');
header('Cache-Control: no-cache, must-revalidate');
header('Expires: '.date("D, d M Y H:i:s GMT", time() - date('Z'))); // Now...
ob_start('ob_gzhandler'); // add gzip compression for good measure
echo '<?xml version="1.0" encoding="iso-8859-1"?>'; // php chokes on this so it must be done this way
?>[/code]
If you are bothered about the .xml extension use mod_write to correct that and the .xml URL will remain active. To do that just put the following in .htaccess.[code=php]<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^baltimore-aikido-news.xml$ baltimore-aikido-news.php
</IfModule>[/code]
Regarding the etag... this will not automatically be sent any longer.[CODE]http://localhost/baltimore-aikido-news.xml
GET /baltimore-aikido-news.xml HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8) Gecko/20051111 Firefox/1.5
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cache-Control: max-age=0
HTTP/1.x 200 OK
Date: Tue, 10 Jan 2006 13:02:30 GMT
Server: Apache/2.0.55 (Win32) PHP/5.1.1
X-Powered-By: PHP/5.1.1
[color=red]Cache-Control: no-cache, must-revalidate
Expires: Tue, 10 Jan 2006 13:02:30 GMT
Content-Encoding: gzip[/color]
Vary: Accept-Encoding
Content-Length: 69
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
[color=red]Content-Type: application/xml[/color]
[/CODE]
[code=php]<?php // This is baltimore-aikido-news.php
header('Content-Type: application/xml');
header('Cache-Control: no-cache, must-revalidate');
header('Expires: '.date("D, d M Y H:i:s GMT", time() - date('Z'))); // Now...
ob_start('ob_gzhandler'); // add gzip compression for good measure
echo file_get_contents('baltimore-aikido-news.xml');
?>[/code]
0.1.9 — BETA 5.24