son 11 Posted June 18, 2012 Report Share Posted June 18, 2012 In a php file I tried to generate xml and hoped thatheader('Content-Type: text/xml');at top would just do this... It doesn't. I can see the xml correctly formed in source code, but on page only the standard subscribe to feed message shows without the items from database... Is it not possible to use php file for xml? Thanks,Son Quote Link to post Share on other sites
Ingolme 1,020 Posted June 18, 2012 Report Share Posted June 18, 2012 Is this supposed to be an RSS feed? Quote Link to post Share on other sites
Guest So Called Posted June 18, 2012 Report Share Posted June 18, 2012 (edited) I'm generating my sitemap.xml using PHP with no problem. I'm using this: header('Content-type: text/xml;charset=utf-8'); I'm also sending Last-Modified and Etag headers, but I doubt that is your problem. Save your source that the PHP generates, then rename it to something .XML and see if that works as a static document. Perhaps you think your document is correctly formed but it isn't. Edited June 18, 2012 by So Called Quote Link to post Share on other sites
birbal 168 Posted June 19, 2012 Report Share Posted June 19, 2012 it sounds like you are trying to use RSS or ATOM. if it like so you have to use appropriate MIME type for them application/atom+xml: <=atom feedsapplication/rss+xml<=rss http://en.wikipedia.org/wiki/Internet_media_type#See_also <=Resource. Quote Link to post Share on other sites
son 11 Posted June 19, 2012 Author Report Share Posted June 19, 2012 Thanks for all your inputs. You put me in right direction... The main issue was that text from db contained a lot of markup stuff which I did not realise until I checked code in detail. I use now strip_tags() before generating the xml, copied the generated source code into xml file and checked this on successfully with http://feedvalidator.org.It is looking good now as the usualy rss screen comes up, but just to double-check:To have news.php withheader('Content-Type: text/xml');that is supposed to act as rss file (and is well-formed) is common practice/ok to use? As there is a lot of changing data from db I have no option to do this static. This is my first rss straight from db and want to make sure that I check all eventualities... Son Quote Link to post Share on other sites
birbal 168 Posted June 19, 2012 Report Share Posted June 19, 2012 header('Content-Type: text/xml');that is supposed to act as rss file the content type of rss feed should be like posted in post #4 It may be possible to use text/xml as feed, its depend on the browser/feed burner how they want to handle it or they will accept it or not. It is wise to follow the standard and use appropriate content type which is set for RSS to be compatible with everyone. Quote Link to post Share on other sites
Ingolme 1,020 Posted June 19, 2012 Report Share Posted June 19, 2012 If there's mark-up in the database information, surround it with <![CDATA[ ]]> tags or use htmlspecialchars(). (Since this is XML, htmlentities() will cause invalid entities) As mentioned, the content-type header should be application/rss+xml Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.