Forum Moderators: open
I get no error or any warning when i create only 100 xml files.
Please help me how can I generate these rss files for all of my products.
thanx.
In your situation, I would use a server-side scripting language to generate the feeds dynamically, on demand. Since you already have them in a database, grabbing the information, wrapping it in XML, and delivering it over the web is a breeze.
For instance, if I request a URL like
http://example.com/feed.php?productid=12345
then my script would output XML describing product 12345.
Is your server capable of server scripting? There are many flavours: PHP, C#, Java, ColdFusion, Perl, Ruby... etc
http://example.com/feed.php?productid=12345
That's the query string I mentioned. It's a name : value pair that can be evaluated by your receiving PHP script as part of the $_GET superglobal. So in this case, $_GET['productid'] would contain the value 12345. Take that attribute, and after filtering and checking it of course, use the value in your SQL SELECT statement to retrieve the record WHERE id={value}.
<?php
mysql_connect [ca.php.net]( your db credentials go here )
header [ca.php.net]("content-type: text/xml");
$id = $_GET['id'];
$xmloutput = "";
$sqlquery = "SELECT * FROM your_table WHERE id = ".$id;
$result = mysql_query [ca.php.net]($sqlquery);
$xmloutput .= "<?xml version=\"1.0\"?>";
$xmloutput .= "<root>";
while($row = mysql_fetch_array [ca.php.net]($result)){
$xmloutput .= "<node>". htmlspecialchars [ca.php.net]($row['your_column_name']) ."</node>";
}
$xmloutput .= "</root>";
echo $xmloutput;
?>
Use PHP to build your XML as a string. When the xml is complete, output it using echo or print().
Note the header() command, which gives the HTTP response an XML mimetype, and the <?xml ?> declaration itself which is part of the document.
Get this working first. Then you'll be able to retrieve XML via a URL like this:
http://example.com/myscript.php?id=12345
Because of that header, it will return a bona fide XML Document, and will be delivered just like it was a real *.xml file sitting on your server.
What I'd do after that is use a little Apache rewriting magic to map that script to a regular expression pattern, so I could get the same XML by requesting this:
http://example.com/12345.xml
there are so many choices
When I'm building an XML feed or API, I look at some of the excellent products available from Yahoo as examples of "doing it right". That's not an endorsement of their services per se; it's a recommendation if you want to see XML handled and delivered expertly.
All of which can be done with a little SQL and PHP, in a hundred lines or less