php - Search for Values in XML -


this question has answer here:

my xml

<properties> <property>     <refno>001</refno>     <status>active</status>     <type>sp</type>     <description>text text text</description>     <images>       <image>path_here</image>       <image>path_here</image>       <image>path_here</image>     </images> </property> <property>     <refno>002</refno>     <status>active</status>     <type>sp</type>     <description>text text text</description>      <images>       <image>path_here</image>       <image>path_here</image>       <image>path_here</image>     </images> </property> </properties> 

my php code

if ($xml = simplexml_load_file($xml_file_here)) {     foreach($xml->property $i) {         if ($i->refno == "1") {             echo $i->description."<br />".             echo $i->type;         }     } } 

i loop though xml find [refno] value. there way search value without need loop?

you can make use of xpath expression:

// find property element contains refno element "001" foreach ($xml->xpath('//property[contains(refno, "001")]') $node) {     echo (string)$node->description, "\n"; } 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -