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

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.

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. :)

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.