note 54638 modified in function.simplexml-element-xpath by danbrown

From: Date: Wed, 16 Sep 2009 15:54:44 +0000
Subject: note 54638 modified in function.simplexml-element-xpath by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-160696@lists.php.net to get a copy of this message
xpath() can also be used to select elements by their attributes. For a good XPath reference check out: http://www.w3schools.com/xpath/xpath_syntax.asp <?php $string = <<<XML <sizes> <size label="Square" width="75" height="75" /> <size label="Thumbnail" width="100" height="62" /> <size label="Small" width="112" height="69" /> <size label="Large" width="112" height="69" /> </sizes> XML; $xml = simplexml_load_string($string); $result = $xml->xpath("//size[@label='Large']"); // print the first (and only) member of the array echo $result[0]->asXml(); ?> The script would print: <size label="Large" width="112" height="69"/> --was-- xpath() can also be used to select elements by their attributes. For a good XPath reference check out: http://www.w3schools.com/xpath/xpath_syntax.asp <?php $string = <<<XML <sizes> <size label="Square" width="75" height="75" /> <size label="Thumbnail" width="100" height="62" /> <size label="Small" width="112" height="69" /> <size label="Large" width="112" height="69" /> </sizes> XML; $xml = simplexml_load_string($string); $result = $xml->xpath("//size[@label='Large']"); // print the first (and only) member of the array echo $result[0]->asXml(); ?> The script would print: <size label="Large" width="112" height="69"/> http://php.net/manual/en/function.simplexml-element-xpath.php

« previous php.notes (#160696) next »