/    Sign up×
Community /Pin to ProfileBookmark

Noob looking for help

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?

to post a comment
PHP

26 Comments(s)

Copy linkTweet thisAlerts:
@SpectreReturnsDec 20.2005 — [code=php]header('Content-type: application/xml');
// rest of parsing commands[/code]
Copy linkTweet thisAlerts:
@CharlesauthorDec 20.2005 — Thanks, but that doesn't seem to do it.Error loading stylesheet:

An XSLT stylesheet does not have an XML mimetype:http://www.baltimoreaikido.com/rss.xsl.php[/quote]
Is it possible that it is choking on the XML declaration?
Copy linkTweet thisAlerts:
@ShrineDesignsDec 20.2005 — you're using php to generate the xsl template?

you will need to send a header for that as well[code=php]<?php
header('Content-Type: application/xml');
// ...
?>[/code]
Copy linkTweet thisAlerts:
@CharlesauthorDec 20.2005 — you're using php to generate the xsl template?

you will need to send a header for that as well[code=php]<?php
header('Content-Type: application/xml');
// ...
?>[/code]
[/QUOTE]
That's exactly what I'm doing, but I get an error on line 2. The prolog of my XSL file is something like:&lt;?php header('Content-Type: application/xml'); ?&gt;
&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
Copy linkTweet thisAlerts:
@bokehDec 20.2005 — <?php header('Content-Type: application/xml'); ?>

<?xml version="1.0" encoding="iso-8859-1"?>[/code][/QUOTE]
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.[code=php]<?php echo '<?xml version="1.0" encoding="iso-8859-1"?>'; ?>[/code]
Copy linkTweet thisAlerts:
@CharlesauthorDec 20.2005 — 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".

Besides, I'm very much a noob when it comes to PHP.

And thanks for the hint, I'll give it a try. I just wish that there was a more elegant solution.
Copy linkTweet thisAlerts:
@bokehDec 20.2005 — 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).
Copy linkTweet thisAlerts:
@CharlesauthorDec 20.2005 — 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.
Copy linkTweet thisAlerts:
@CharlesauthorDec 21.2005 — It looks like I'm up and running. Thanks!
Copy linkTweet thisAlerts:
@SpectreReturnsDec 21.2005 — Teamwork! Co-operation! Team Battle Star, unite!
Copy linkTweet thisAlerts:
@gameguy43Dec 21.2005 — i think i remember seeing you on css forums, and believe me, youre playin with the big boys out here. server-side scripting is hardly ever "elegant" looking.
Copy linkTweet thisAlerts:
@CharlesauthorDec 21.2005 — erver-side scripting is hardly ever "elegant" looking.[/QUOTE]It is when you are using Perl
Copy linkTweet thisAlerts:
@bokehDec 21.2005 — server-side scripting is hardly ever "elegant" looking.[/QUOTE]That's all down to who is writing the script.
Copy linkTweet thisAlerts:
@SheldonDec 21.2005 — clean script is oggd but i never do it, vut is worth while doingit
Copy linkTweet thisAlerts:
@CharlesauthorJan 09.2006 — 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.
Copy linkTweet thisAlerts:
@bokehJan 09.2006 — 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 [URL=http://bokehman.com/get?url=http%3A%2F%2Fwww.baltimoreaikido.com%2Frss.xsl.php&follow_redirects=&submit=Have+a+look%21]the page with my viewer[/URL] to make sure it is being updated. If it is you will know for sure it is a browser caching issue.
Copy linkTweet thisAlerts:
@CharlesauthorJan 09.2006 — At this point the problem isn't with the XSL file but with the XML RSS file, http://www.baltimoreaikido.com/baltimore-aikido-news.xml . I'm thinking that adding an expiration date might help.
Copy linkTweet thisAlerts:
@bokehJan 09.2006 — At the minute Apache is deciding if the page has changed. It is sending an etag and if this is returned by the browser on a subsequent request Apache sends a 304 (no body). Sending that file to the php parser or prepending a php file would stop that behaviour and a 200 would always be returned (unless php specified otherwise).
Copy linkTweet thisAlerts:
@CharlesauthorJan 09.2006 — The server seems to be always sending a 200, the Etag changes each time I upload the file but Firefox doesn't grab the new file. How do I make it do that?
Copy linkTweet thisAlerts:
@bokehJan 09.2006 — For me it sends a 304 on refresh (matching etags). I'm using firefox too.

It doesn't make much sense at all. If your browser recieves a 200 response from the server it will display that page. After all why try the server for a new version and then when it sends one display a cached page?
Copy linkTweet thisAlerts:
@CharlesauthorJan 10.2006 — I don't understand it either, but it night be worth trying to supress the Etag and sending an expiration. If only I knew how to do either.
Copy linkTweet thisAlerts:
@bokehJan 10.2006 — Here's one way you could do it... Rename the file with [I].php[/I]. At the beginning of the file remove [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.

Using the above, here is how the headers look:[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]
Copy linkTweet thisAlerts:
@CharlesauthorJan 12.2006 — Thankls for your help, and I'm sorry to be drawing this out but...

I'm using a field driven editor to generate the RSS. I was about to write a Perl script to post process the file, adding the PHP you suggested, before uploading but then I realized that it would make more sense to do everything on the server. Only I'm getting a little lost in the PHP documentation.

Here's what I'd like to try. I'd like baltimore-aikido-news.php to output those headers and then read and send baltimore-aikido-news.xml.
Copy linkTweet thisAlerts:
@bokehJan 12.2006 — [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]
Copy linkTweet thisAlerts:
@CharlesauthorJan 14.2006 — Thanks, it's working quite well.
Copy linkTweet thisAlerts:
@bokehJan 14.2006 — Happy to help!
×

Success!

Help @Charles spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...