Jump to content

xml in php file


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 post
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 post
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 post
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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...