0

I have following xml file but facing problem in parsing the attributes of staff list.How to get staff:name and 'staff:image`.

<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:course="https://www.edx.org/api/course/elements/1.0/" xmlns:staff="https://www.edx.org/api/staff/elements/1.0/" version="2.0">
<channel>
 <title>edX.org course feed</title>
 <link>https://www.edx.org/api/v2/report/course-feed/rss</link>
 <atom:link rel="first" href="https://www.edx.org/api/v2/report/course-feed/rss"/>
 <atom:link rel="last" href="https://www.edx.org/api/v2/report/course-feed/rss?page=12"/>
 <atom:link rel="previous" href="https://www.edx.org/api/v2/report/course-feed/rss?page=11"/>
 <atom:link href="https://www.edx.org/api/v2/report/course-feed/rss" rel="self" type="application/rss+xml"/>
 <description>edX.org - course catalog feed</description>
 <language>en</language>
 <item>
 <title>Quantum Mechanics of Molecular Structures</title>
 <course:instructors>
  <course:staff>
   <staff:name>Kaoru Yamanouchi</staff:name>
   <staff:title/>
   <staff:bio>
     Professor Kaoru Yamanouchi has been Professor of Chemistry at the University of Tokyo since April 1997. His research fields are in physical chemistry; especially, gas phase laser spectroscopy, chemical reaction dynamics, and intense laser science. He is one of the world-leading scientists in the new interdisciplinary research field called ultrafast intense laser science. He has been the recipient of Morino Fellowship endowed by Morino Foundation (1987), Spectroscopical Society of Japan Award for High-Quality Papers (1989), Chemical Society of Japan Award for Young Scientists (1991), Japan IBM Prize (2000), The Best Paper Award of the Laser Society of Japan (2008), and Chemical Society of Japan Award (2015).
   </staff:bio>
   <staff:image>
    https://www.edx.org/sites/default/files/person/image/photoyamanouchi110x110.jpg
   </staff:image>
   </course:staff>
 <course:staff>
</course:instructors>
</item>
</channel>
</rss>

How can i parse the course:instructors list.
So far my code is:

 $rss = simplexml_load_file('https://www.edx.org/api/v2/report/course-feed/rss?page=12');
 $namespaces = $rss->getNamespaces(true);//Add this line
 echo '<h1>'. $rss->channel->title . '</h1>';
 foreach ($rss->channel->item as $item) {
   $title = $item->title ;
   echo '<h2><a href="'. $item->link .'">' . $title . "</a></h2>";
   $course = $item->children($namespaces['course']);
 }
2
  • Please update your question with the content of $item variable. Commented Nov 10, 2016 at 14:23
  • check this answer. This is another approach. You can also create a functional sample in PhpFiddle. Hope it helps Commented Nov 11, 2016 at 13:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.