2016-06-20 11 views
0

XMLの検索に2つの条件を追加しようとしています。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 cが示唆していると仕事になります。

$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

おかげのようになります... –