PDA

View Full Version : How do I display content from an XML feed.



Harold Mansfield
12-03-2009, 08:27 PM
You would think by now, I would have an answer to this but I don't.

How in the world do I display the content from an XML data feed on a website, or wordpress blog.
I have looked for an answer to this all over the internet, yet all I find is other people asking the same question and there is never an answer. Some going back as far as 4 years ago.
I even checked the WP forums and every topic on this is unresolved. IOW, no definitive answer.

Seems like it should be simple....I have XML data feeds that have images and text. They are obviously created to be displayed, like an RSS feed, so why then is it so difficult to do something so simple ?


Anyone know an easy solution ?

thx4yrtym
12-03-2009, 09:39 PM
Harold,

I suspected that jQuery could help and did a search and found this:

watch the video

Video Presentation: Manipulating XML With jQuery (http://www.bennadel.com/blog/1637-Video-Presentation-Manipulating-XML-With-jQuery.htm)

hope this helps,

Harold Mansfield
12-03-2009, 10:03 PM
Thanks, I'll check it out after the game.

Harold Mansfield
12-03-2009, 11:18 PM
Harold,

I suspected that jQuery could help and did a search and found this:

watch the video

Video Presentation: Manipulating XML With jQuery (http://www.bennadel.com/blog/1637-Video-Presentation-Manipulating-XML-With-jQuery.htm)

hope this helps,

Looks good but it says right up front that it doesn't work in IE.
Anyone else have any suggestions.

billbenson
12-03-2009, 11:29 PM
I wrote a php script that converted xml from an RSS feed to html several years ago. I'd have to some digging to find it.

Check out some of these at hot scripts. They may do what you want. You can do in in js, but if you use a php script to display it, it will be html and the search engines can see it. JS will be invisible to the search engines.

PHP XML & PHP | Scripts & Programs | Hot Scripts (http://www.hotscripts.com/category/php/scripts-programs/xml-php/)

Harold Mansfield
12-04-2009, 12:07 AM
Thanks, I'll check those out.
It's the most frustrating thing ever. There are no real answers anywhere online.
Tons of affiliate programs offer XML feeds, not RSS or anything simple...they all have XML feeds but none of them give any instructions or help on what to do with them or how to make them work.

I have found hundreds of people asking the same question and not one answer, anywhere.
Every time I get on this, I look around for a couple of days...never find a concrete answer or even a decent example and give up. Next thing you know, 2 years later, I still have no idea what to do with an affiliates XML feed.

billbenson
12-04-2009, 02:29 AM
And here's some more scripts I found. Hopefully VG or somebody knows more about this.

Xml Affiliate Feed Script (scriptlance) - MisterSoft FreeLance Projects (http://www.mistersoft.org/freelancing/scriptlance/2009/04/PHP-XML-MySQL-Xml-Affiliate-Feed-Script-1240176034.html)

vangogh
12-04-2009, 03:06 AM
Sorry, but this isn't anything I've done either. I would think you need to parse the xml file to display the way you want, however each affiliate probably isn't so consistent in their xml and would need some custom parsing. RSS is essentially a standardized xml format.

Maybe there's a way you could take the xml you have and convert it to rss.

billbenson
12-04-2009, 03:21 AM
Eborg, are a lot of sites putting up a lot of different affiliate feeds? I noticed in my search that you can buy software for specific feeds such as Amazon. I suspect they are all similar, but not the same. Looks like each feed may be unique, if even slightly.

Maybe you could have a generic script written that you could go in and modify for each feed. A bit of a pain, but you could capitalize on things that your competition isn't doing like putting various feeds on a site? If they are paying money for software for each feed like the Amazon software, they aren't going to be buying all of them??

Harold Mansfield
12-04-2009, 11:57 AM
Eborg, are a lot of sites putting up a lot of different affiliate feeds? I noticed in my search that you can buy software for specific feeds such as Amazon. I suspect they are all similar, but not the same. Looks like each feed may be unique, if even slightly.

Maybe you could have a generic script written that you could go in and modify for each feed. A bit of a pain, but you could capitalize on things that your competition isn't doing like putting various feeds on a site? If they are paying money for software for each feed like the Amazon software, they aren't going to be buying all of them??

Yes, a lot of affiliates offer feeds, actually almost all of them.
I have software and scripts for Amazon auto posting and a free script that handles E-bay categories w/keywords...and of course there's BANS store software for ebay. I think those work with "tagging".

A lot of affiliates offer RSS feeds as well, which are pretty simple...Title-Description-Link which you can control....but many of them also offer XML feeds...especially music and ticket programs that display Dates, Prices, Label, Venue, and images which seem to be raw feeds with only basic parameters set.

Each feed is unique. It seems that you can't use a generic reader for XML feeds since they all have different parameters.

Displaying XML feeds is a question I see webmasters asking all over forums and there is never a definitive answer, probably because one script won't work across the board.

I do have a script to display the particular feed that I am working with right now, I can adjust the styling of it, but I can't control how many items to display.
Here it is:


<html>
<style>
<!--
body{font-family: Verdana;}
-->
</style>
<? //XML CODE STARTS HERE
$affiliateid =12555;
$file = file_get_contents("http://www.xxxxxxxxxxx.com/affiliates/xml/nye.xml?sktag=12555"); //change this to whichever feed you wish to use
$xml = simplexml_load_string($file);
foreach($xml->events->event as $x){ //This loops around each event

//Get the event details
$id = $x['id'];
$name = $x->name;
$link = $x['link'];
$date = $x->date;
$desc = $x->shortdesc;
$doorsopen = $x->doorsopen;
$doorsclose = $x->doorsclose;
$image = $x->image;
$venue = $x->venue->name;
$tickets = $x->tickets;

$link = str_replace("sktag=12555","sktag=".$affiliateid,$link); //Change the default link to our affiliate link to allow tracking


//Start displaying info below

// Alternatively you could insert the event details into your datebase
// For example INSERT INTO events(id,name,link,date,venue) VALUES ('$id','$name','$link','$date','$venue')

echo "<h2>".$name."</h2>";

echo "<img src='$image' style='float:left;width:75px;margin:5px;'";
echo "<p>".$desc."</p>";
echo "<strong>Venue: $venue</strong> / ";
echo "<strong>Doors open: $doorsopen - $doorsclose</strong>";echo "<p><a href='$link'>More Info</a></p>";
foreach($tickets->ticket as $t){ //loop around the tickets and show information for each ticket
$ticketname = $t->name;
$ticketPrice = $t->faceValue;
$status = $t->status['statuscode']; //1 = Available. 100 = sold out
if($status==1){
echo "<li>".$ticketname." &pound;".$ticketPrice." <a href='$link'><strong>(Buy Tickets)</strong></a></li>";
}elseif($status==100){
echo "<li>".$ticketname." &pound;".$ticketPrice." <span style='color:red'>(SOLD OUT)</span></li>";
}
}

echo "<hr/>";
}

?>
</body></html>

Looks like I'll have to spend a day learning the language to get it to display the way I want.

billbenson
12-04-2009, 02:00 PM
Try this. My code changes are in bold. It should display 10 rows. You can change the number of rows by change the 10 in my bold to the number you want.

This is a good example of why you want to pick up some php. Not necessarily to write scripts from scratch, but to be able to do modifications to get stuff that is close to what you need to meet exactly what you need.





<html>
<style>
<!--
body{font-family: Verdana;}
-->
</style>
<? //XML CODE STARTS HERE
$affiliateid =12555;
$file = file_get_contents("http://www.xxxxxxxxxxx.com/affiliates/xml/nye.xml?sktag=12555"); //change this to whichever feed you wish to use
$xml = simplexml_load_string($file);
foreach($xml->events->event as $x){ //This loops around each event

//Get the event details
$id = $x['id'];
$name = $x->name;
$link = $x['link'];
$date = $x->date;
$desc = $x->shortdesc;
$doorsopen = $x->doorsopen;
$doorsclose = $x->doorsclose;
$image = $x->image;
$venue = $x->venue->name;
$tickets = $x->tickets;

$link = str_replace("sktag=12555","sktag=".$affiliateid,$l ink); //Change the default link to our affiliate link to allow tracking
$i=0;

//Start displaying info below

// Alternatively you could insert the event details into your datebase
// For example INSERT INTO events(id,name,link,date,venue) VALUES ('$id','$name','$link','$date','$venue')

echo "<h2>".$name."</h2>";

echo "<img src='$image' style='float:left;width:75px;margin:5px;'";
echo "<p>".$desc."</p>";
echo "<strong>Venue: $venue</strong> / ";
echo "<strong>Doors open: $doorsopen - $doorsclose</strong>";echo "<p><a href='$link'>More Info</a></p>";
foreach($tickets->ticket as $t){ //loop around the tickets and show information for each ticket
$ticketname = $t->name;
$ticketPrice = $t->faceValue;
$status = $t->status['statuscode']; //1 = Available. 100 = sold out


if($status==1 && $i<10){
echo "<li>".$ticketname." &pound;".$ticketPrice." <a href='$link'><strong>(Buy Tickets)</strong></a></li>";
}elseif($status==100){
echo "<li>".$ticketname." &pound;".$ticketPrice." <span style='color:red'>(SOLD OUT)</span></li>";

++$i;
}
}

echo "<hr/>";
}

?>
</body></html>

Harold Mansfield
12-04-2009, 03:09 PM
That didn't work...gave me an error message from the exec.php plug in.


Parse error: syntax error, unexpected T_STRING in /usr/www/virtual/eborg9/www.124bpms.com/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()'d code on line 25

Code works fine without the edits.

billbenson
12-04-2009, 03:17 PM
Make sure you have the semicolon line 26. Something in that line is causing the problem.

$i=0;

billbenson
12-04-2009, 03:34 PM
Eborg, I just tried your original pasted code and it didn't work. Maybe the forum didn't like it. email me the code in a text file bbenson at iti-resources.com

Bill

Harold Mansfield
12-04-2009, 03:57 PM
Eborg, I just tried your original pasted code and it didn't work. Maybe the forum didn't like it. email me the code in a text file bbenson at iti-resources.com

Bill

Just sent it. Thanks !

Harold Mansfield
12-04-2009, 04:14 PM
Eborg, I just tried your original pasted code and it didn't work. Maybe the forum didn't like it. email me the code in a text file bbenson at iti-resources.com

Bill

That's because the code I pasted doesn't have the XML feed in it, I "X'ed" it out just to show the code part.

Harold Mansfield
12-05-2009, 06:36 PM
Just wanted to update. Bill was able to help and adjusted the code to display. In case anyone has similar problems, here is the code that he edited. Note: this probably won't wok with any other XML feed, since they all have different parameters to display but it may help point you in the right direction if you have a point of reference or a script that works with your specific feed that needs adjusting.


<html>
<style>
<!--
body{font-family: Verdana;}
-->
</style>
<? //XML CODE STARTS HERE

//my change
$i=0;

$affiliateid =12555;
$file = file_get_contents("http://www.xxxxxxxx.com/affiliates/xml"); //change this to whichever feed you wish to use
$xml = simplexml_load_string($file);


foreach($xml->events->event as $x){ //This loops around each event
if ($i <10){
//Get the event details
$id = $x['id'];
$name = $x->name;
$link = $x['link'];
$date = $x->date;
$desc = $x->shortdesc;
$doorsopen = $x->doorsopen;
$doorsclose = $x->doorsclose;
$image = $x->image;
$venue = $x->venue->name;
$tickets = $x->tickets;

$link = str_replace("sktag=12555","sktag=".$affiliateid,$link); //Change the default link to our affiliate link to allow tracking
//Start displaying info below

// Alternatively you could insert the event details into your datebase
// For example INSERT INTO events(id,name,link,date,venue) VALUES ('$id','$name','$link','$date','$venue')

echo "<h2>".$name."</h2>";

echo "<img src='$image' style='float:left;width:75px;margin:5px;'";
echo "<p>".$desc."</p>";
echo "<strong>Venue: $venue</strong> / ";
echo "<strong>Doors open: $doorsopen - $doorsclose</strong>";echo "<p><a href='$link'>More Info</a></p>";
foreach($tickets->ticket as $t){ //loop around the tickets and show information for each ticket
$ticketname = $t->name;
$ticketPrice = $t->faceValue;
$status = $t->status['statuscode']; //1 = Available. 100 = sold out


if($status==1){
echo "<li>".$ticketname." &pound;".$ticketPrice." <a href='$link'><strong>(Buy Tickets)</strong></a></li>";

}elseif($status==100){
echo "<li>".$ticketname." &pound;".$ticketPrice." <span style='color:red'>(SOLD OUT)</span></li>";
}
}
echo "<br/>";
echo "<hr/>";
++$i;
}
}
?>
</body></html>


I did a little styling and eliminated a few parameters for space, but it does exactly what I needed. The feed displays ticket information for upcoming events in the sidebar on this site:
124 Beats Per Minute - The Latest News in Trance, House and Electronic Dance Music (http://www.124bpms.com)

Thanks again Bill :)

camp185
01-19-2010, 04:37 PM
I wrote a php script that converted xml from an RSS feed to html several years ago. I'd have to some digging to find it.

Check out some of these at hot scripts. They may do what you want. You can do in in js, but if you use a php script to display it, it will be html and the search engines can see it. JS will be invisible to the search engines.

PHP XML & PHP | Scripts & Programs | Hot Scripts (http://www.hotscripts.com/category/php/scripts-programs/xml-php/)

Creating a custom script using PHP may be the easiest way. That is what I did, similarly, several years ago.