0

I am trying to retrieve RSS feed using php. The xml has many different nodes. I am not sure how to display <dc:>,<rdf:>,<syn:> node.

feed

<item>xxx</item>
....
....
<dc:name>John</dc:name>    //I am not sure how to get this content
<dc:title>Manager</dc:title>
<syn:updateTime>1970-01-01</syn:updateTime>
<rdf:Seq>
   <rdf:li rdf:resource="http://xxx/>
   <rdf:li rdf:resource="http://xxx/>
</rdf:Seq>

php

$contents= file_get_contents($url);

$results=new SimpleXMLElement($contents);

    //not sure what I can do to display those special nodes...
    foreach ($results->channel as $node):

        echo $node->item; //only show item content  

    endforeach;
Nightfirecat
  • 11,432
  • 6
  • 35
  • 51
FlyingCat
  • 14,036
  • 36
  • 119
  • 198

2 Answers2

2

Try this:

$xmlStr= simplexml_load_string($contents);

Then you can use print_r to dump the object $xmlStr

echo print_r($xmlStr)

or in a browswer

echo "<pre>".print_r($xmlStr)."</pre>";

This way you can inspect the object if that is what you're attempting to do. To access individual values/nodes:

echo $xmlStr->node

and that should return the contents of the node.

Not sure what happens if you do this, but you can also try the following, but it depends on the content of $xmlStr perhaps...:

foreach($xmlStr as $key => $value) {
    print "$key => $value\n";
}
Tucker
  • 7,017
  • 9
  • 37
  • 55
1

If it's a standards compliant RSS feed, why not use simplepie or something like it? A dedicated parser is nearly always better than rolling your own :)

Lusitanian
  • 11,012
  • 1
  • 41
  • 38