How can from the below xml . I am using php SimpleXmlElement to parse the entire xml.I am getting all the details other than this element .
<feed xmlns:im="http://itunes.apple.com/rss" xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<id>
https://itunes.apple.com/us/rss/customerreviews/id=977/sortBy=mostRecent/xml
</id>
<title>iTunes Store: Customer Reviews</title>
<updated>2013-11-19T05:55:27-07:00</updated>
<entry>
<updated>2013-11-14T05:27:00-07:00</updated>
<id>895482313</id>
<title>Still </title>
<content type="text">
The app continues to .
</content>
<im:contentType term="Application" label="Application"/>
<im:voteSum>0</im:voteSum>
<im:voteCount>0</im:voteCount>
<im:rating>4</im:rating>
<im:version>3.1</im:version>
<author>
<name>LIMHP2010</name>
<uri>https://itunes.apple.com/us/reviews/id15104323</uri>
</author>
<link rel="related" href="https://itunes.apple.com/us/review?id=722846977&type=Purple%20Software"/>
<content type="html">
<table border="0" width="100%"> <tr> <td> <table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr valign="top" align="left"> <td width="100%"> <b><a href="https://itunes.apple.com/us/app/tricycle-magazine/id722846977?mt=8&uo=2">Still Crashing during updating</a></b><br/> <font size="2" face="Helvetica,Arial,Geneva,Swiss,SunSans-Regular"> </font> </td> </tr> </table> </td> </tr> <tr> <td> <font size="2" face="Helvetica,Arial,Geneva,Swiss,SunSans-Regular"><br/>On iPhone 5s, iOS 7.0.3 - <br/><br/>Customer service was fantastic at fixing the problem of zooming into much. The problem of crashing while attempting to update purchases continues.<br/><br/>The app continues to be essentially useless.</font><br/> </td> </tr> </table>
</content>
</entry>
</feed>
You should use DOMXpath::evaluate(). SimpleXml hides functions from you. In this case I think your problem are namespaces. PHP automatically registers the namespaces of the current context (the second argument of query()/evaluate()
), you don't really want that, it can interfere with your own namespace definition. The third argument of query()/evaluate()
disables the automatic registration.
$dom = new DOMDocument();
$dom->loadXml($xml);
$xpath = new DOMXpath($dom);
// register the namespaces you would like to use with own prefixes
$xpath->registerNamespace('itunes', 'http://itunes.apple.com/rss');
$xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
var_dump(
'Entries: '.$xpath->evaluate('count(//atom:entry)', NULL, FALSE)
);
// fetch the list of entry nodes
$entries = $xpath->evaluate('//atom:entry', NULL, FALSE);
foreach ($entries as $entry) {
// fetch values from the entry node children
var_dump(
$xpath->evaluate('string(atom:title)', $entry, FALSE),
$xpath->evaluate('string(atom:content)', $entry, FALSE),
$xpath->evaluate('string(itunes:contentType/@label)', $entry, FALSE),
$xpath->evaluate('string(itunes:version)', $entry, FALSE),
$xpath->evaluate('number(itunes:rating)', $entry, FALSE)
);
}
Unlike query(), evaluate() can return scalar values, too.
string(10) "Entries: 1"
string(6) "Still "
string(24) "
The app continues to .
"
string(11) "Application"
string(3) "3.1"
float(4)