note 82986 modified in function.simplexml-element-xpath by danbrown
| From: | danbrown@php.net | Date: | Wed, 16 Sep 2009 15:52:30 +0000 |
| Subject: | note 82986 modified in function.simplexml-element-xpath by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-160685@lists.php.net to get a copy of this message | ||
If you want to search multiple values from xml on the behalf or one value then this code can be
helpfull to you.
if there is:
<Record>
<country>Pakistan</country>
<code>+92</code>
<Value>100<Value>
</Record>
then try this one:
<?php
$sxe = simplexml_load_file("countries.XML");
foreach($sxe->xpath('//RECORD') as $item) {
$row = simplexml_load_string($item->asXML());
$v = $row->xpath('//country[. ="Pakistan"]');
if($v[0]){
print $item->country;
print $item->code;
print $item->value;
}
}
?>
--was--
If you want to search multiple values from xml on the behalf or one value then this code can be
helpfull to you.
if there is:
<Record>
<country>Pakistan</country>
<code>+92</code>
<Value>100<Value>
</Record>
then try this one:
$sxe = simplexml_load_file("countries.XML");
foreach($sxe->xpath('//RECORD') as $item) {
$row = simplexml_load_string($item->asXML());
$v = $row->xpath('//country[. ="Pakistan"]');
if($v[0]){
print $item->country;
print $item->code;
print $item->value;
}
}
http://php.net/manual/en/function.simplexml-element-xpath.php