
December 13th, 2012, 03:30 PM
|
|
Contributing User
|
|
Join Date: Oct 2004
Posts: 197
Time spent in forums: 2 Days 11 h 20 m 40 sec
Reputation Power: 9
|
|
|
Finding the parent node from the child namespace in RSS Feed
I've been at this for days and I think I almost have it, but I'm missing a huge piece. Here's the sample RSS feed.
Code:
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:uoc="http://pathhere.com">
<channel>
<title>News Feed</title>
<link>http://www.mylink.com</link>
<description>News.</description>
<language>en-us</language>
<lastBuildDate>Wed, 12 Dec 2012 10:53:22 -0500</lastBuildDate>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<generator>Generator text</generator>
<item>
<title>Story 1</title>
<link>http://www.mylink.com/story1.php</link>
<description>Description Here</description>
<author>Jane Doe</author>
<pubDate>Fri, 7 Dec 2012 17:48:46 -0500</pubDate>
<uoc:category>Academics,Campus,Current Students,Faculty,Scholarship</uoc:category>
<uoc:tags>story, sample, find me</uoc:tags>
<uoc:featured>no</uoc:featured>
</item>
<item>
<title>Story 2</title>
<link>http://www.mylink.com/story2.php</link>
<description>Description Here</description>
<author>John Doe</author>
<pubDate>Fri, 7 Dec 2012 17:48:46 -0500</pubDate>
<uoc:category>Academics,Campus,Current Students</uoc:category>
<uoc:tags>story, sample, find me</uoc:tags>
<uoc:featured>no</uoc:featured>
</item>
<item>
<title>Story 3</title>
<link>http://www.mylink.com/story3.php</link>
<description>Description Here</description>
<author>John Doe</author>
<pubDate>Fri, 7 Dec 2012 17:48:46 -0500</pubDate>
<uoc:category>Faculty,Music,Staff</uoc:category>
<uoc:tags>story, sample, find me</uoc:tags>
<uoc:featured>no</uoc:featured>
</item>
</channel>
</rss>
I need to find every story where the uoc:category node contains Faculty and/or Staff. So far I have
Code:
if (!isset($filePath)) $filePath = '/pathto/rss/news.xml';
if (file_exists($filePath)) {
// read the file
$items = simplexml_load_file($filePath);
$stories = $items->xpath('//item/uoc:category/text()[contains(.,"Faculty")]');
var_dump($stories);
}
The successfully pulls the entries, but it only contains the uoc:category node and not the parent and sibling information. I suspect I'm approaching this in the completely wrong way or that there is one extra step I missed, but at this point I'm lost. Help?
|