Reputation: 133
I want to check in a xml if there is a node with the value "Hotel Hafen Hamburg".
But I get the error.
SimpleXMLElement::xpath(): Invalid predicate on line 25
You can view the xml here.
http://de.sourcepod.com/dkdtrb22-19748
Until now I have written the following code.
$apiUmgebungUrl = "xml.xml";
$xml_umgebung = simplexml_load_file($apiUmgebungUrl);
echo $nameexist = $xml_umgebung->xpath('boolean(//result/name[@Hotel Hafen Hamburg');
Upvotes: 1
Views: 6643
Reputation: 20780
It seems that your parantheses and brackets do not close properly at the end of your XPath expression - it should end on ])
.
Also, what is Hotel Hafen Hamburg? If it is an attribute called value
, your value check should look like this:
[@value="Hotel Hafen Hamburg"]
You cannot just write @
and then a value, without specifying where that value is supposed to be.
EDIT: Looking at the Xml document, it seems that Hotel Hafen Hamburg is supposed to be the text content of the <name>
element. Therefore, try looking for a text node with that value rather than an attribute:
boolean(//result/name[text() = "Hotel Hafen Hamburg"])
Upvotes: 7