PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 13th, 2012, 03:30 PM
Bastion Bastion is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 197 Bastion User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #2  
Old December 14th, 2012, 02:02 PM
Bastion Bastion is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 197 Bastion User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 11 h 20 m 40 sec
Reputation Power: 9
I'm closer now. I figured out how to search using the xpath:

Code:
$items = $items->xpath('//item[uoc:category[contains(.,"Faculty")]]


So now, the code is

Code:
if (file_exists($filePath)) {
		// read the file
		$items = simplexml_load_file($filePath);
		$items = $items->xpath('//item[uoc:category[contains(.,"Faculty")]]|item[uoc:category[contains(.,"Staff")]]');
		usort($items, " sortPubdate"); // to included function 
		foreach ($items AS $story) {
			echo '<h3>' . $story->title . '</h3>';
			echo '<p>' . $story->description . '</p>';
		}
	}


The last step I need to figure out is how to get the namespace to be part of the $items array created by xpath. Research so far shows that it's not possible, but that's in articles from 2007. Any updated articles that show otherwise?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Finding the parent node from the child namespace in RSS Feed

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap