Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts

    Exclamation rss to html: retrieving namespace node values from wordpress feed

    Hi All

    I have the following
    PHP Code:
    $rss = new DOMDocument();
    $rss->load('http://thelostgirl2014.wordpress.com/feed/');

    $feed = array();
    foreach (
    $rss->getElementsByTagName('item') as $node) {
        
    $item = array ( 
            
    'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
            
    'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
            
    'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
            
    'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
            );
        
    array_push($feed$item);
    }

    $limit 3;
    for(
    $x=0;$x<$limit;$x++) {
        
    $title str_replace(' & '' &amp; '$feed[$x]['title']);
        
    $link $feed[$x]['link'];
        
    $description $feed[$x]['desc'];
        
    $date date('l F d, Y'strtotime($feed[$x]['date']));
        echo 
    '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';
        echo 
    '<small><em>Posted on '.$date.'</em></small></p>';
        echo 
    '<p>'.$description.'</p>';

    which pulls out the data needed, but i want to pull out the data from the following nodes:
    content => content:encoded
    images => media:content
    number of comments => slash:comments
    the comments themselves => comments

    i tried adding this to get the value of the media url namespace
    Code:
    'photos' => $node->getElementsByTagNameNS('http://thelostgirl2014.wordpress.com/feed/', 'content')->item(0)->nodeValue,
    but that throws an error
    Code:
     Trying to get property of non-object
    this is a snippet of the rss feed
    Code:
    <item>
    		<title>Achievements</title>
    		<link>http://thelostgirl2014.wordpress.com/2014/01/13/achievements/</link>
    		<comments>http://thelostgirl2014.wordpress.com/2014/01/13/achievements/#comments</comments>
    		<pubDate>Mon, 13 Jan 2014 03:20:32 +0000</pubDate>
    		<dc:creator><![CDATA[thelostgirl2014]]></dc:creator>
    				<category><![CDATA[Uncategorized]]></category>
    
    		<guid isPermaLink="false">https://thelostgirl2014.wordpress.com/?p=8</guid>
    		<description><![CDATA[Well, in the last few months I have achieved so much…from joining a cruiseship to simply eating prawns!! I have never been a prawn fan, never liked the look of them so never tried them! But today, at Mozarts Restaurant in Funchal, Madeira I had a fresh mushroom and prawn risotto which was delicious! To […]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelostgirl2014.wordpress.com&blog=62611577&post=8&subd=thelostgirl2014&ref=&feed=1" width="1" height="1" />]]></description>
    				<content:encoded><![CDATA[<p><a href="http://thelostgirl2014.files.wordpress.com/2014/01/20140113-031825-am.jpg"><img src="http://thelostgirl2014.files.wordpress.com/2014/01/20140113-031825-am.jpg?w=696" alt="20140113-031825 am.jpg" class="alignnone size-full" /></a></p>
    <p>Well, in the last few months I have achieved so much…from joining a cruiseship to simply eating prawns!! </p>
    <p>I have never been a prawn fan, never liked the look of them so never tried them!<br />
    But today, at Mozarts Restaurant in Funchal, Madeira I had a fresh mushroom and prawn risotto which was delicious! </p>
    <p>To me this is a massive step for me, I have always been afraid of trying new food but seeing as I’m away I’m keen to try new things…so prawns are my latest thing…<br />
    The best thing was…the three course meal came with free champagne and wine woohoo!! Bonus!! €37 well spent me thinks!!</p><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thelostgirl2014.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thelostgirl2014.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelostgirl2014.wordpress.com&blog=62611577&post=8&subd=thelostgirl2014&ref=&feed=1" width="1" height="1" />]]></content:encoded>
    			<wfw:commentRss>http://thelostgirl2014.wordpress.com/2014/01/13/achievements/feed/</wfw:commentRss>
    		<slash:comments>0</slash:comments>
    		<georss:point>32.642638 -16.923540</georss:point>
    		<geo:lat>32.642638</geo:lat>
    		<geo:long>-16.923540</geo:long>
    		<media:content url="http://2.gravatar.com/avatar/5f747606b6bc78986250229230fe693f?s=96&d=identicon&r=G" medium="image">
    			<media:title type="html">thelostgirl2014</media:title>
    		</media:content>
    
    		<media:content url="http://thelostgirl2014.files.wordpress.com/2014/01/20140113-031825-am.jpg" medium="image">
    			<media:title type="html">20140113-031825 am.jpg</media:title>
    		</media:content>
    	</item>
    any help would be greatly appreciated!!!

    Luke
    Last edited by LJackson; 02-05-2014 at 11:51 PM.

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Posts
    462
    Thanks
    0
    Thanked 20 Times in 20 Posts
    Code:

    'content' =>$node->getElementByTagName('content')->item(0)->nodeValue,
    Try adding the 's'
    $node->getElementsByTagName('content')
    Last edited by c1lonewolf; 02-04-2014 at 11:17 PM.
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    For projects using MediaTypes (MIMETypes) visit E-BAM.net -(updated weekly)

    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts
    ah that might help, good spot

    i have ammended my code

    PHP Code:
    <?php
    $rss 
    = new DOMDocument();
    $rss->load('http://thelostgirl2014.wordpress.com/feed/');

    $feed = array();
    foreach (
    $rss->getElementsByTagName('item') as $node)
    {
        
    $item = array ( 
            
    'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
            
    'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
            
    'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
            
    'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
            
    'content' => $node->getElementsByTagName('encoded')->item(0)->nodeValue,
            
    'comments' => $node->getElementsByTagName('comments')->item(0)->nodeValue,
            
    'photos' => $node->getElementsByTagNameNS('http://thelostgirl2014.wordpress.com/feed/''content')->item(0)->nodeValue,
            );
        
    array_push($feed$item);
    }

    $limit 3;
    for(
    $x=0;$x<$limit;$x++)
    {
        
    $title str_replace(' & '' &amp; '$feed[$x]['title']);
        
    $link $feed[$x]['link'];
        
    $description $feed[$x]['desc'];
        
    $content $feed[$x]['content'];
        
    $comments $feed[$x]['comments'];
        
    $photos $feed[$x]['photos'];
        
    $date date('l F d, Y'strtotime($feed[$x]['date']));?>
        
        <div class="feed">
            <div class="feed-title">
                <a href="<?php echo $link?>" title="<?php echo $title?>"><?php echo $title?></a>
            </div>
            
            <div class="feed-date">
                <small><em>Posted on <?php echo $date?></em></small>
            </div>
            
            <div class="feed-description">
                <?php echo $photos?>
            </div>
        </div><?php
    }?>
    but this line
    PHP Code:
    'photos' => $node->getElementsByTagNameNS('http://thelostgirl2014.wordpress.com/feed/''content')->item(0)->nodeValue
    causes this error
    Code:
    Trying to get property of non-object
    any ideas?

    Thanks for your help
    Luke
    Last edited by LJackson; 02-05-2014 at 11:55 PM.

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts
    ok i got it sorted in the end had to go down the simplexml path.

    I had it working for a couple of hours and then bag it went tits up now im getting an error saying invalid argument supplied in foreach but i havent changed anything

    here is my code
    PHP Code:
    $feed = file_get_contents("https://www.facebook.com/feeds/page.php?format=rss20&id=152842238112142");
    $xml = new SimpleXmlElement($feed);
    foreach ($xml->channel->item as $entry)
    {
        //Use that namespace
        $namespaces = $entry->getNameSpaces(true);?>
        <div class="feed">
            <div class="feed-title">
                <a href="<?php echo $entry->link?>" title="<?php echo $entry->title?>"><?php echo $entry->title?></a>
            </div>
            <div class="feed-date">
                <small><em>Posted on <?php echo date('l F d, Y'strtotime($entry->pubDate))?></em></small>
            </div>
            <div class="feed-description">
                <?php echo strip_tags($entry->description)?>
            </div>
          </div><?php
    }
    could someone kindly look at the feed and check i am using the correct arguments in the foreach loop please...

    Luke


  •  

    LinkBacks (?)


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •