PDA

View Full Version : Read xml DOM


eugui
07-17-2009, 07:27 PM
hi..i have this code to read rss/atom:


function rss_to_array($tags, $array, $url) {
//RSS and ATOM
$doc = new DOMdocument();
@$doc->load($url);
$rss_array = array();
foreach($tags as $tag) {
if ($doc->getElementsByTagName($tag)) {
foreach($doc->getElementsByTagName($tag) AS $node) {
$items = array();
foreach($array AS $key => $values) {
$items[$key] = array();
foreach($values as $value) {
if ($itemsCheck = $node->getElementsByTagName($value)) {
for( $j=0 ; $j < $itemsCheck->length; $j++ ) {
if (($attribute = $itemsCheck->item($j)->nodeValue) != "") {
$items[$key][] = utf8_decode($attribute);
} else if ($attribute = $itemsCheck->item($j)->getAttribute('term')) {
$items[$key][] = utf8_decode($attribute);
} else if ($itemsCheck->item($j)->getAttribute('rel') == 'alternate') {
$items[$key][] = $itemsCheck->item($j)->getAttribute('href');
}
}
}
}
}
array_push($rss_array, $items);
}
}
}
return $rss_array;
}

$rss_item_tags = array('item', 'entry');

$rss_tags = array(
'title' => array('title'),
'description' => array('description', 'content', 'summary'),
'link' => array('link', 'feedburner'),
'category' => array('category'),
'pubDate' => array('pubDate'),
'dc:creator' => array('dc:creator')
);

$url = utf8_encode("http://feeds.feedburner.com/sedentario");

$rssfeed = rss_to_array($rss_item_tags, $rss_tags, $url);

print_r($rssfeed);


but i have a problem, the function dont get the value of namespace like dc:creator, wfw:commentRss... why?

tks