Hey,
Is there a way I can query multiple tags in a RSS feed with xpath and return them as a variable to loop. That’s not very well explained, so; this is the code I’m using to query the title of each <item> in an RSS feed:
$dom = new DomDocument();
$dom -> load( "news.xml" );
$xp = new DomXPath( $dom );
echo( "news items are<br />" );
$title = $xp -> query( "/rss/channel/item/title" );
foreach( $title as $node )
{
echo( "<h1>". $node -> textContent . "</h1>" );
}
The Structure of the RSS feed is:
<item>
<title>First Title</title>
<link>a link</link>
<description>a description</description>
</item>
What I would like to do for the result of the foreach statement would be something like this:
echo( "<h1>". $title . "</h1>" );
echo( "<p>". $description . "<br />" );
echo( $link . "</p>" );
Basically, what I want to do is load the text content of each of the child elements in <item> into separate specific variables so that I have full control over them, so I can use them however I wish, like:
(assuming the text content between <link> and </link> was loaded into $link, etc.)
echo ( 'a href=“' . $link . '”>' . $title .'</a><br />');
echo ( $description );
Or
echo( "<h1>". $title . "</h1>" );
echo( "<p>". $description . "<br />" );
echo( $link . "</p>" );
And then loop the above for every instance that the parent <item> is found in the xml / rss.
Any help would be greatly appreciated. Even if anyone has a link to a tutorial that might deal with the above, I don’t mind doing some leg work. Just can’t seem to find anything that deals with what I’m looking for.
Cheers.