Php 提取物<;im:评级>;苹果饲料

Php 提取物<;im:评级>;苹果饲料,php,xml,simplexml,Php,Xml,Simplexml,如何从下面的xml中删除。我正在使用php SimpleXmlElement解析整个xml。我正在获取除此元素之外的所有详细信息 <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=mostRe

如何从下面的xml中删除。我正在使用php SimpleXmlElement解析整个xml。我正在获取除此元素之外的所有详细信息

<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>

https://itunes.apple.com/us/rss/customerreviews/id=977/sortBy=mostRecent/xml
iTunes商店:客户评论
2013-11-19T05:55:27-07:00
2013-11-14T05:27:00-07:00
895482313
仍然
该应用程序继续运行。
0
0
4.
3.1


在iphone5s上,iOS 7.0.3-

客户服务非常擅长解决放大到太多的问题。在尝试更新购买时崩溃的问题仍然存在。

该应用程序基本上仍然没有用处。

您应该使用DOMXpath::evaluate()。SimpleXml对您隐藏函数。在这种情况下,我认为您的问题是名称空间。PHP自动注册当前上下文的名称空间(query()/evaluate()的第二个参数),如果您不想注册,它可能会干扰您自己的名称空间定义。
query()/evaluate()
的第三个参数禁用自动注册

$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)
  );
}
与query()不同,evaluate()也可以返回标量值

string(10) "Entries: 1"
string(6) "Still "
string(24) "
The app continues to .
"
string(11) "Application"
string(3) "3.1"
float(4)
我能做到这一点
$review->children('im',true)->使用
simplexmlement()


回答。

这对我来说很有用。非常感谢。还有一个问题是,如何从这个xmlgot中获取作者的详细信息。这将返回作者名$xpath->evaluate('string(atom:author/atom:name)',$entry);如果不知道,请添加第三个参数,原子名称空间注册处于活动状态。这会影响性能,但更重要的是,$entry上下文节点上的xmlns:atom或xmlns:itunes属性会覆盖您自己的命名空间定义。这可能会导致意外行为。酷。在centos5+PHP5.2.7上运行的脚本中添加第三个参数无法正常工作。删除后,它开始工作:)它是在PHP5.3.3中添加的。