Jump to content

xml in php file


son

Recommended Posts

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

Guest So Called

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 by So Called
Link to comment
Share on other sites

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

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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...