note 83922 added to function.simplexml-element-xpath
| From: | paul at pmtlogic dot com | Date: | Wed, 18 Jun 2008 19:17:44 +0000 |
| Subject: | note 83922 added to function.simplexml-element-xpath | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140569@lists.php.net to get a copy of this message | ||
xpath doesn't seem to be able to handle single quotes embedded in the query itself. For
instance, I want to find geo coordinates in an xml file based on country name.
xml snippet:
<zones>
<zone country="Cote d'Ivoire" fullName="Yamoussoukro"
geo="6.82,-5.28" id="1050"><url prefix="1001"
value="fiji.html" /><url prefix="1002" value="C"
/></zone>
</zones>
The following code does not work:
$xml = simplexml_load_file("my.xml");
$result = $xml->xpath("//zone[@country='Cote d\'Ivoire']");
foreach ( $result[0]->attributes() as $key => $val ) {
print "<div class='coords'>$key: $val</div>\n";
}
I have tried many variations on the embedded single quote (i.e. escape codes) but with no result.
W3C offers no explanation either.
In addition, there doesn't seem to be any way of embedding wildcards in the attribute value
(you can embed wildcards in the attribute name). Otherwise the following might be a reasonable
substitute in this context:
$result = $xml->xpath("//zone[@country='Cote d*Ivoire']");
----
Server IP: 213.246.42.8
Probable Submitter: 57.69.14.65
----
Manual Page -- http://www.php.net/manual/en/function.simplexml-element-xpath.php
Edit -- https://master.php.net/note/edit/83922
Del: integrated -- https://master.php.net/note/delete/83922/integrated
Del: useless -- https://master.php.net/note/delete/83922/useless
Del: bad code -- https://master.php.net/note/delete/83922/bad+code
Del: spam -- https://master.php.net/note/delete/83922/spam
Del: non-english -- https://master.php.net/note/delete/83922/non-english
Del: in docs -- https://master.php.net/note/delete/83922/in+docs
Del: other reasons-- https://master.php.net/note/delete/83922
Reject -- https://master.php.net/note/reject/83922
Search -- https://master.php.net/manage/user-notes.php