DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   RSS, Web Services and SOAP (http://www.daniweb.com/forums/forum151.html)
-   -   Is it possible to code inside XML file for an RSS Feed? (http://www.daniweb.com/forums/thread198196.html)

dudegio Jun 18th, 2009 12:33 am
Is it possible to code inside XML file for an RSS Feed?
 
Hello guys,

I need an expert advice if it is possible to code inside an XML file? Example, news.xml whereas in that file you have to code connecting to MySQL database then retrieve data. Generated data is the XML required tags for the RSS and will be written in similar file that is the news.xml.

All I know is, an XML file only contains XML tags and no coding. Any idea please share. Thank you very much.

GIO

pritaeas Jun 18th, 2009 7:43 am
Re: Is it possible to code inside XML file for an RSS Feed?
 
Not possible from within an XML file. However, you could for example use a .htaccess file to redirect news.xml to a php file which will generate and output the XML.

dudegio Jun 18th, 2009 10:05 pm
Re: Is it possible to code inside XML file for an RSS Feed?
 
Quote:

Originally Posted by pritaeas (Post 893654)
Not possible from within an XML file. However, you could for example use a .htaccess file to redirect news.xml to a php file which will generate and output the XML.

Hi Can you teach me how please? thank you. :)

pritaeas Jun 25th, 2009 7:15 am
Re: Is it possible to code inside XML file for an RSS Feed?
 
Hi. You can use this in your htaccess file

RewriteRule ^news.xml$ "news.php" [L]

It redirects news.xml to news.php.

In news.php you can use:

header("Content-Type: application/xml; charset=ISO-8859-1");

to state that your output will be xml. After this, just output your generated tags.

Sorry for the late reply, I've been away.

Airshow Jul 2nd, 2009 8:46 am
Re: Is it possible to code inside XML file for an RSS Feed?
 
Hi,

Pritaeas solution is neat but does rely on Apache MOD_REWRITE being enabled, which is not always the case.

Another way to do it is to request the worker page (eg. news.php) directly and specify any content criteria in the query part of the url.

For example
http://www.blah.domain/feeds/news.php?s=fashion&d=5&c=france

The values s, d, c would be entirely of your own choosing (I just invented these ones) and would be interpreted server-side from $_GET in PHP (or ASP, JSP etc) to compose corresponding SQL, perform the database lookup, and finally compose and serve the output XML (or HTML or whatever is your final product).

Some RSS feeds are served this way, eg,
http://www.blog.nl/rss.php?blogId=17&profile=rss20
http://www.stern.de/standard/rss.php?channel=sport-motor

though it is more common to find path-mapped urls eg.;
http://www.pheedo.com/f/newscientist_motoring-tech

Airshow


All times are GMT -4. The time now is 8:26 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC