PHP: Parse remote XML Feed....

I am trying to parse this feed, but I seem to be missing something. Instead of getting the categories list, I just get this:
object(SimpleXMLElement)#1 (1) {
  ["@attributes"]=>
  array(2) {
    ["fixed"]=>
    string(3) "yes"
    ["scheme"]=>
    string(52) "http://gdata.youtube.com/schemas/2007/categories.cat"
  }
}

This is the feed:
http://gdata.youtube.com/schemas/2007/categories.cat?hl=en-US

This is the code I have so far:


<?php
	$feedURL = 'http://gdata.youtube.com/schemas/2007/categories.cat?hl=en-US';
    
    // read feed into SimpleXML object
    $xml = simplexml_load_file($feedURL);
    var_dump($xml);
    print_r($xml);
?>

Open in new window

interclubsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hernst42Commented:
You need to specify the namespace like this:
// read feed into SimpleXML object
$xml = simplexml_load_string($data);
foreach($xml->children("http://www.w3.org/2005/Atom") as $category) {
    echo $category->saveXML(), PHP_EOL;
    /** @var $category SimpleXMLElement */
    foreach ($category->attributes() as $a) {
        /** @var $a SimpleXMLElement */
        echo $a->getName(), (string) $a, PHP_EOL;
    }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
InsoftserviceCommented:
not tested as i did not found right xml file

$xmlkey      = file_get_contents($feedURL);
 $xml = simplexml_load_string( $xmlkey );
if(!empty($xml->rootnode)){
foreach( $xml->rootnode as $aClient )
{
echo (string)$aClient->childnote;
}

you can use foreach as per ur need.
searching for good example of xml for testing.but it would work, if proper node name is provided
0
InsoftserviceCommented:
hi,
test code is below try it out
<?php
$feedURL = 'http://www.mangalsutrabandhan.com/horoscope.rss';

           $xmlkey      = file_get_contents($feedURL);
             $xml = simplexml_load_string( $xmlkey );

            if(!empty($xml->channel))
            {
                  foreach( $xml->channel as $aClient )
                  {
                        print_r($aClient);
                        echo (string)$aClient->title;
                        echo '<br>';
                        echo (String)$aClient->description;
                        echo '<br>';
                        echo (String)$aClient->link;
                  }
            }
?>
(string),(int) =>is very much important over here. it had created lots of problem for me when i was new for xml part.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

InsoftserviceCommented:
srry missed out uncomment print_r($aClient) .

if you want to check the xml just do echo '<pre>';print_r($xmlkey);print_r($xml); to get the node structure
0
interclubsAuthor Commented:
Awesome, thanks!
0
InsoftserviceCommented:
did u tried my answer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.