if you are parsing the feed yourself then the following code can be used to parse the feeds. In the endElement function you can do anything you want. This code I’m using in a widget I wrote to parse RSS feeds.:
function startElement($xp,$name,$attributes) {
global $item,$currentElement; $currentElement = $name;
//the other functions will always know which element we're parsing
if ($currentElement == 'ITEM') {
//by default PHP converts everything to uppercase
$item = true;
// We're only interested in the contents of the item element.
////This flag keeps track of where we are
}
}
function endElement($xp,$name) {
global $item,$currentElement,$title,$description,$link,$rssCount;
if ($name == 'ITEM' && $rssCount < $this->maxRssEntries) {
// If we're at the end of the item element, display
// the data, and reset the globals
echo "<div class='custom-feed'>";
echo "<div class='custom-feed-title'><a href='" . $link . "'>$title</a></div>";
echo "<div class='custom-feed-desc'>$description</div>";
echo "</div>";
$rssCount += 1;
$title = '';
$description = '';
$link = '';
$item = false;
}elseif($name == 'ITEM'){
$title = '';
$description = '';
$link = '';
$item = false;
}
}
function characterDataHandler($xp,$data) {
global $item,$currentElement,$title,$description,$link;
if ($item) {
//Only add to the globals if we're inside an item element.
switch($currentElement) {
case "TITLE":
$title .= $data;
// We use .= because this function may be called multiple
// times for one element.
break;
case "DESCRIPTION":
$description.=$data;
break;
case "LINK":
$link.=$data;
break;
}
}
}
function readFeeds($feed) {
global $rssCount;
$fh = fopen($feed,'r');
// open file for reading
$xp = xml_parser_create();
// Create an XML parser resource
xml_set_element_handler($xp, array($this,"startElement"), array($this,"endElement"));
// defines which functions to call when element started/ended
xml_set_character_data_handler($xp, array($this,"characterDataHandler"));
while ($data = fread($fh, 4096)) {
if($rssCount < $this->maxRssEntries){
if (!xml_parse($xp,$data)) {
return 'Error in the feed';
}
}else
break;
}
}
Sorry in advance if I misunderstood your question.
[signature moderated Please read the Forum Rules]