son Posted June 18, 2012 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 Link to comment Share on other sites More sharing options...
Ingolme Posted June 18, 2012 Share Posted June 18, 2012 Is this supposed to be an RSS feed? Link to comment Share on other sites More sharing options...
Guest So Called Posted June 18, 2012 Share Posted June 18, 2012 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. Link to comment Share on other sites More sharing options...
birbal Posted June 19, 2012 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. Link to comment Share on other sites More sharing options...
son Posted June 19, 2012 Author 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 Link to comment Share on other sites More sharing options...
birbal Posted June 19, 2012 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. Link to comment Share on other sites More sharing options...
Ingolme Posted June 19, 2012 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.