SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru hifigrafix's Avatar
    Join Date
    Oct 2005
    Location
    Nashville, TN
    Posts
    628
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simplexml Issue - Can't Access More Than 3 Items

    I'm using simplexml to grab a simple feed from google. Everything is fine BUT I'm only able to access 3 of the children from the item.

    Example:

    Code:
    SimpleXMLElement Object
    (
        [title] => Like A Woman Lyrics <b>Jamie O&#39;Neal</b>
        [link] => http://www.lyrics-celebrities.anekatips.com/like-a-woman-lyrics-jamie-oneal
        [description] => I know I've got a really good life I'm a good wife, and a mama to a baby girl. I'm a little bit of everything to everyone It's like I'm riding on a Tilt-A-World It's hard not to get caught up in the spinnings And the laundry and the ...
        [publisher] => Lyrics Song Words
        [creator] => lyrics-admin
        [date] => Sat, 14 Feb 2009 03:19:35 GMT
    )
    When calling these I can only access "title", "link" and "description". It's acting like "publisher", "creator" and "date" don't even exist. it's not giving me an error or anything rather it's just coming up empty.

    PHP Code:
            $title $entry->title;
                
    $link $entry->link;
                
    $description $entry->description;
                
    $publisher $entry->publisher;
                
    $creator $entry->creator;
                
    $date $entry->date;
                
                    echo 
    $title."<br />";
                echo 
    $link."<br />";
                echo 
    $description."<br />";
                echo 
    $publisher."<br />"// EMPTY
                
    echo $creator."<br />"// EMPTY
                
    echo $date// EMPTY 

  2. #2
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    61 Post(s)
    Tagged
    0 Thread(s)
    Does the XML look like <dc:publisher>? You can't access those namespaced nodes in exactly the same way as the others. Try $dc = $entry->children('dc', TRUE); $publisher = $dc->publisher; (or look on the manual page for SimpleXMLElement::children).
    Salathe
    Software Developer and PHP Manual Author.

  3. #3
    SitePoint Guru hifigrafix's Avatar
    Join Date
    Oct 2005
    Location
    Nashville, TN
    Posts
    628
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your reply.

    The data isn't namespaced. I'm enclosing the full feed just for example.

    Code:
    SimpleXMLElement Object
    (
        [channel] => SimpleXMLElement Object
            (
                [title] => Adam Gregory, -90210 - Google Blog Search
                [link] => http://blogsearch.google.com/blogsearch?hl=en&ie=ISO-8859-1&num=10&q=Adam+Gregory,+-90210
                [description] => Google Blog Search Results: <b>266,474</b> results for <b>Adam Gregory, -90210</b> - showing 1 through 10
                [totalResults] => 266474
                [startIndex] => 1
                [itemsPerPage] => 10
                [item] => Array
                    (
                        [0] => SimpleXMLElement Object
                            (
                                [title] => Goodwill for World Orphans Day 2009 – <b>Adam Gregory</b> and Buddy Jewell
                                [link] => http://www.countrymusictattletale.com/2009/11/02/goodwill-for-world-orphans-day-2009-adam-gregory-and-buddy-jewell
                                [description] => He will join fellow ambassadors Stella Parton and <b>Adam Gregory</b> at the The People's Church East Lawn, near the corner of Highway 96 and Mack Hatcher Parkway in Franklin, Tennessee, 4:00 pm CST on Monday, November 9, ...
                                [publisher] => Country Music Tattle Tale
                                [creator] => Country Girl
                                [date] => Mon, 02 Nov 2009 21:50:01 GMT
                            )
    
                        [1] => SimpleXMLElement Object
                            (
                                [title] => What It Takes Lyrics <b>Adam Gregory</b>
    
                                [link] => http://www.lyrics-celebrities.anekatips.com/what-it-takes-lyrics-adam-gregory
                                [description] => Song Words by Artist / Band : <b>Adam Gregory</b> Lyrics Title : “What It Takes” Available on Album : <b>Adam Gregory</b> Released : October 27, 2008. Music Genre : Country Music. Use printable version of What It Takes Lyrics <b>Adam Gregory</b> ...
                                [publisher] => Lyrics Song Words
                                [creator] => lyrics-admin
                                [date] => Sat, 14 Feb 2009 03:05:27 GMT
                            )
    
                        [2] => SimpleXMLElement Object
                            (
                                [title] => <b>Adam Gregory</b>: 10/20/09: The ICM Awards &amp; Update On WWJD
                                [link] => http://adamgregory.blogspot.com/2009/10/102009-icm-awards-update-on-wwjd.html
                                [description] => So all in all it was a great visit to LA. Other than that I'm continually working on music and keeping myself busy. I hope y'all have a great day, and week and God  Bless! ag). Posted by <b>Adam Gregory</b> at 12:04 PM ...
                                [publisher] => Adam Gregory
                                [creator] => Adam Gregory
                                [date] => Wed, 21 Oct 2009 19:04:01 GMT
                            )
    
                        [3] => SimpleXMLElement Object
                            (
                                [title] => Single Review: “What It Takes” by <b>Adam Gregory</b> « Country Music Central
                                [link] => http://countrycentral.wordpress.com/2008/10/28/single-review-what-it-takes-by-adam-gregory/
                                [description] => Single Review: “What It Takes” by <b>Adam Gregory</b>. 2008 October 28. by cowboybleau. At least this guy is consistant. The already established Canadian country star crosses over to the US with his second radio single in this country, ...
                                [publisher] => Country Music Central
                                [creator] => cowboybleau
                                [date] => Tue, 28 Oct 2008 03:07:57 GMT
                            )
    
                        [4] => SimpleXMLElement Object
                            (
                                [title] => “Memory Like That” <b>Adam Gregory</b>
    
                                [link] => http://songlyrics.topliriklagu.com/memory-like-that-song-lyric-artist-adam-gregory.htm
                                [description] => Memory Like That <b>Adam Gregory</b> there are moments in your life that are frozen in your mind that will change the heart of how you feel forever and i remember the rain the sky.
                                [publisher] => Song Lyrics and Guitar Chords
                                [creator] => Dewi
                                [date] => Mon, 28 Sep 2009 14:12:03 GMT
                            )
    
                        [5] => SimpleXMLElement Object
                            (
                                [title] => Company 81 Spring 2010 Line with <b>Adam Gregory</b>
                                [link] => http://www.denimblog.com/look-book/company-81-spring-2010-line-with-adam-gregory/
                                [description] => Here is your sneak peek at the Company 81 Spring 2010 Line with <b>Adam Gregory</b> modeling. Mmmm I gotta say they picked a fine male specimen to show off their line! I love how this brand has started with Men's clothing first, ...
                                [publisher] => Jeans Blog- Designer Jeans - Designer Jeans sales | Denim Blog.com
                                [creator] => Liznie
                                [date] => Tue, 08 Sep 2009 14:37:05 GMT
                            )
    
                        [6] => SimpleXMLElement Object
                            (
                                [title] => Nous Model Management | MEN: <b>ADAM GREGORY</b> | BY SPECIAL ARRANGEMENT
                                [link] => http://nousmodelsmen.blogspot.com/2009/09/adam-gregory-available-for-special.html
                                [description] => <b>ADAM GREGORY</b> | BY SPECIAL ARRANGEMENT. Bookmark and Share. Labels: <b>Adam Gregory</b>. 0 comments: Post a Comment · Newer Post Older Post Home. Subscribe to: Post Comments (Atom). ABOUT. NOUS MODEL MANAGEMENT: Nous is the premier boutique ...
                                [publisher] => Nous Model Management | MEN
                                [creator] => NOUS MODEL MANAGEMENT
                                [date] => Fri, 11 Sep 2009 00:22:01 GMT
                            )
    
                        [7] => SimpleXMLElement Object
                            (
                                [title] => <b>Adam Gregory</b>-Me Too
                                [link] => http://www.lovelyrics.info/9997-adam-gregory-me-too.html
                                [description] => There are fences, that need to be mended There's a stray cow off from the heard, that needs to be defended By law, we can't fight underneath the  stars He sits in his stacks and strums his guitar I tell you what the world could use ...
                                [publisher] => Love LYRICS
                                [creator] => admin
                                [date] => Tue, 27 Oct 2009 10:05:02 GMT
                            )
    
                        [8] => SimpleXMLElement Object
                            (
                                [title] => &quot;WWJD What Would Jesus Do?&quot; Feature Film Premiere Starring John <b>...</b>
    
                                [link] => http://identi.ca/notice/13046632
                                [description] => "WWJD What Would Jesus Do?" Feature Film Premiere Starring John Schneider, Maxine Bahns, <b>Adam Gregory</b> - http://www.g-trends.info/?p=2199.
                                [publisher] => mylake timeline
                                [creator] => mylake
                                [date] => Tue, 27 Oct 2009 16:14:16 GMT
                            )
    
                        [9] => SimpleXMLElement Object
                            (
                                [title] => THE ESCAPIST [Kara Spin-Off] -- S01
                                [link] => http://www.kryptonsite.com/forums/showthread.php?t=133855
                                [description] => <b>Adam Gregory</b> as Jake Collins Kelly Rowan as Allura In-Ze Peyton List as Lucy Lane with Michael Rosenbaum as Lex Luthor Recurring Guest Stars: Tom Welling as Clark Kent / Kal-El Erica Durance as Lois Lane Cassidy Freeman as Tess Mercer ...
                                [publisher] => KryptonSite Message Forums
                                [creator] => michel_90
                                [date] => Fri, 16 Oct 2009 09:45:00 GMT
                            )
    
                    )
    
            )
    
    )

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Can you post the source XML or URL here?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Guru hifigrafix's Avatar
    Join Date
    Oct 2005
    Location
    Nashville, TN
    Posts
    628
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anthony,

    I was wrong - when I looked at the XML source I noticed that it actually was namespaced and thanks to salathe's direction I got it figured out although his example didn't work for me.

    I actually had to use this:

    PHP Code:
    $dc $entry->children('http://purl.org/dc/elements/1.1/'); 
    Thanks for the help everyone!

  6. #6
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    61 Post(s)
    Tagged
    0 Thread(s)
    I thought so, the listing of namespaced nodes in the print_r output was confusing me for a while. What version of PHP are you using out of interest? Using the namespace prefix (ala. children('dc', TRUE)) should be available from 5.2.0.

    Good to see you got it sorted anyway. :-)
    Salathe
    Software Developer and PHP Manual Author.

  7. #7
    SitePoint Guru hifigrafix's Avatar
    Join Date
    Oct 2005
    Location
    Nashville, TN
    Posts
    628
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea I'm still on 5.0.4 with this server.


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
  •