【发布时间】:2015-07-10 17:17:45
【问题描述】:
我有这个 xml 文件:
<friends>
<friend>
<name>xxx</name>
<pays>France</pays>
</friend>
<friend>
<name>yyy</name>
<country>France</country>
</friend>
<friend>
<name>zzz</name>
<country>USA</country>
</friend>
</friends>
为了获取我的数据,我使用了这个 php 代码:
$xml = simplexml_load_file('friends.xml');
$friendsXML = $xml->friend;
效果很好,但会返回所有朋友。
现在我只想检索来自法国的朋友:
country = 'france'.
谁能帮我做这件事?
【问题讨论】:
-
简单xpath:
//country[text()='france']/.. -
或者更好的副本:Implementing condition in XPath