SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Jul 2004
    Location
    USA
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SimpleXML Parsing Child Attribute

    Hello,

    I have been searching google for a while now, but have not found a solution that works properly, which is kind of frustrating.

    I have a sample entry from an XML:
    <item>
    <title>PongOut: Anniversary Edition</title>
    <link>http://www.hallpass.com/media/pongout-anniversary.html</link>
    <description>Play Pong and Breakout simultaneously like never before with particle effects, new power ups, new levels and more! </description>
    <pubDate>Fri, 27 Feb 09 13:24:33 CST</pubDate>

    <media:title>PongOut: Anniversary Edition</media:title>
    <media:description>Play Pong and Breakout simultaneously like never before with particle effects, new power ups, new levels and more! </media:description>
    <media:keywords>breakout,pong</media:keywords>
    <media:thumbnail url="http://media1.hallpass.com/imageStorage/15911.jpg" width="80" height="60" />
    </item>
    I have the loop working to parse it, but I cant figure out a way to get the thumbnail URL out. There was another post on here that mentioned using something like $dc->children->attributes()->url (dont have the exact code, not on my computer) but that returned a node error.

    Any help would be appreciated,

    Thanks
    BKerr

  2. #2
    derrrp
    Join Date
    Aug 2006
    Location
    earth
    Posts
    923
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Does the php manual help?

    SimpleXMLElement:attributes
    No, I REALLY dislike having to use Joomla.

  3. #3
    SitePoint Evangelist
    Join Date
    Jul 2004
    Location
    USA
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by crowden View Post
    Hi,

    Does the php manual help?

    SimpleXMLElement:attributes
    Not really, the problem im having is accessing the element because of the :
    BKerr

  4. #4
    SitePoint Evangelist
    Join Date
    Jul 2004
    Location
    USA
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Back on my computer, this is my code
    PHP Code:
    $feedURL "http://hallpass.com/rss/games.xml"
    $sxml simplexml_load_file($feedURL);

    foreach (
    $sxml->channel->item as $item)
    {     
        
    $article = array();
        
    $title $item->title;
        
    $description $item->description;
        
        
    $img = (string) $item->children('http://search.yahoo.com/mrss/')->thumbnail->attributes()->url
                 
        echo 
    "<b>" $title "</b><BR>" $description "<BR>URL: " $img "<BR><BR>";

    And I get this error message: Node no longer exists on the $img line
    BKerr

  5. #5
    SitePoint Evangelist
    Join Date
    Jul 2004
    Location
    USA
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dumb me, Solved.
    BKerr


Bookmarks

Posting Permissions

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