Having problems creating XML feed

Hi there. I’ve found this forum useful a few times as a reader and decided to register because I have been going round in circles online trying to answer this problem.

I need to create an XML feed, pulling a custom query from MySQL. I have a site with a built in feed that exports stories using , and but the problem is I need to create a custom feed and I can’t seem to work out how to create my own elements.

I need a feed like this but I don’t know how to actually create, or validate or show the custom elements (it is for a wine database):

Name of wine 2001 £200.00 http://... etc Cs of 3 Magnums

I manage to run the query I need and create a file that outputs into source code all my data, but when I view the PHP file of the feed, I only see the title with the link and no other content.

I’m ideally looking for a sample of a customised XML file output. I’ve tried several I have found but none of them talk about custom elements.

Can you post you php code? I believe you just need to echo your custom tags like: echo ‘$price’, there should not be any problem.

Thanks for your reply. The main feed script I tried to use references a feed creation script.

I found one online that looked a little too simplified but have tried that:

Below is the code for my feed script:
[php]<?php
include “admin_includes.php”;

//SET XML HEADER
header('Content-type: text/xml');

//CONSTRUCT RSS FEED HEADERS
$output = '<rss version="2.0">';
$output .= '<channel>';
$output .= '<title>Site name</title>';
$output .= '<description>Feed description</description>';
$output .= '<link>http://www.website.com/</link>';
$output .= '<copyright>Copyright details</copyright>';

$s =“select f_wine_product_id, f_wine_product_vintage, f_wine_product_label, f_wine_product_size, f_wine_product_vis, f_wine_product_percase, f_wine_product_pricepercase, f_wine_label_name, f_wine_size_name from WINE_PRODUCT, WINE_LABEL, WINE_SIZE where f_wine_product_label=f_wine_label_id and f_wine_product_size=f_wine_size_id and f_wine_product_vis=1 order by f_wine_label_name”;
$r=sql_do($s);
$c=mysql_num_rows($r);
if($c>0){
for($i=0;$i<$c;$i++){
$row=mysql_fetch_row($r);
$output .= ‘’;
$output .= ‘’.$row[7].’’;
$output .= ‘’.$row[1].’’;
$output .= ‘…/index.php?wineprofile=’.$row[0].’’;
$output .= ‘£’.$row[6].’’;
$output .= ‘cs of ‘.$row[5].’ ‘.$row[8].’’;
$output .= ’ ';
}
}

//CLOSE RSS FEED

$output .= ‘’;
$output .= ‘’;

//SEND COMPLETE RSS FEED TO BROWSER
echo($output);

?> [/php]

This outputs a live php page that shows the browser only the name of the feed and the description.
If I look at the source of the file, it is serving data - a sample of that is below:

[php]Site nameFeed descriptionhttp://www.website.com/Copyright detailsBrane Cantenac2005http://www.888finewine.com/index.php?wineprofile=45£500.00cs of 12 75cl Bottle Calon Ségur2000http://www.888finewine.com/index.php?wineprofile=14£800.00cs of 12 75cl Bottle Carruades de Lafite2008http://www.888finewine.com/index.php?wineprofile=72£4100.00cs of 12 75cl Bottle Cheval Blanc1999http://www.888finewine.com/index.php?wineprofile=65£3900.00cs of 12 75cl Bottle Cheval Blanc2001http://www.888finewine.com/index.php?wineprofile=64£3400.00cs of 12 75cl Bottle Cheval Blanc2001http://www.888finewine.com/index.php?wineprofile=63£3300.00cs of 6 Magnum (150cl) Cheval Blanc2000http://www.888finewine.com/index.php?wineprofile=69£8900.00cs of 6 Magnum (150cl) Cheval Blanc1998http://www.888finewine.com/index.php?wineprofile=13£4800.00cs of 12 75cl Bottle Clos l’Eglise1998http://www.888finewine.com/index.php?wineprofile=26£475.00cs of 6 75cl Bottle Cos d’Estournel1996http://www.888finewine.com/index.php?wineprofile=7£1300.00cs of 12 75cl Bottle Cos d’Estournel2001http://www.888finewine.com/index.php?wineprofile=16£1400.00cs of 12 75cl Bottle Cos d’Estournel2003http://www.888finewine.com/index.php?wineprofile=41£1800.00cs of 12 75cl Bottle[/php]

The W3C validator says my custom elements are not defined.

Check examples and explanations here: http://base.google.com/support/bin/answer.py?answer=58085

As you can see, they have these two 2 lines at top of xml file, and the second line refers to definition of namespace declaration:

<?xml version="1.0"?> <rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">

Thank you. I am not creating this for Google base but for another feed aggregator which does not give specific instructions about namespace creation.

This is the sample feed they show so I’m just trying to output the same thing from my DB.

[php]<?xml version="1.0" encoding="iso-8859-1" ?>




Chateau Bahans Haut Brion Rouge, Pessac Leognan, France
99.00
2000
Bottle

		<link>http://www.mycompany.com/store/wines/12345</link>
	</wine>
	<wine>
		<wine-name>Chateau Bahans Haut Brion Rouge, Pessac Leognan, France</wine-name>
		<price>650.00</price>
		<vintage>2000</vintage>
		<bottle-size>12 x 750ml</bottle-size>

		<link>http://www.mycompany.com/store/wines/12345-1</link>
	</wine>
	<wine>
		<wine-name>Cloudy Bay Te Koko Sauvignon Blanc, Marlborough, New Zealand</wine-name>
		<price>240.00</price>
		<vintage>2005</vintage>
		<bottle-size>12 x 750ml</bottle-size>

		<link>http://www.mycompany.com/store/wines/32158</link>
	</wine>
	<wine>
		<wine-name>Chateau Ste Michelle Eroica Riesling, Columbia Valley, USA</wine-name>
		<price>14.95</price>
		<vintage>2008</vintage>
		<bottle-size>bottle</bottle-size>

		<link>http://www.mycompany.com/store/wines/65428</link>
	</wine>
	<wine>
		<wine-name>Duval-Leroy Rose de Saignee Brut Champagne</wine-name>
		<price>24.95</price>
		<vintage>NV</vintage>
		<bottle-size>bottle</bottle-size>

		<link>http://www.mycompany.com/store/wines/66587</link>
	</wine>
	<wine>
		<wine-name>Chateau Lafite Rothschild, Pauillac, France</wine-name>
		<price>730.00</price>
		<vintage>1997</vintage>
		<bottle-size>Magnum</bottle-size>

		<link>http://www.mycompany.com/store/wines/11234</link>
	</wine>
</wine-list>
[/php]

Their sample feed does not pass validation at validator.w3.org/feed either.

Sponsor our Newsletter | Privacy Policy | Terms of Service