2016-06-20 78 views
0

我想添加两个条件来搜索我的XML。PHP Xpath简单搜索

考虑这个XML:

<?xml version="1.0"?> 
<votes> 
    <vote> 
    <url>http://www.mydoamin.com</url> 
    <ip>xxx.xxx.xxx.xxx</ip> 
    </vote> 
</votes> 

然后我用:

$xml->xpath("(//votes/vote/[url='Admin' and ip='Group']"); 

但是,让一个无效的表达式错误:

对于单一的条件这个工程:

$xml->xpath("(//votes/vote/ip[contains(text(), '$ip')])"); 

Logi Ç建议的,并会工作:

$xml->xpath("(//votes/vote/ip[contains(text(), '$ip')]) & (//votes/vote/url[contains(text(), '$ip')])"); 

但这种失败 - 警告:的SimpleXMLElement :: XPath的():无效的表达

我在做什么错?

A.

回答

0

vote[之间删除/

的XPath看起来应该像

//votes/vote[url='Admin' and ip='Group'] 
+0

感谢那些完美地工作... –