note 84196 added to function.simplexml-element-xpath
| From: | anemik at osu1 dot php dot net | Date: | Wed, 02 Jul 2008 22:46:39 +0000 |
| Subject: | note 84196 added to function.simplexml-element-xpath | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-141089@lists.php.net to get a copy of this message | ||
If you want to find easly all records satisfying some condition in XML data like
....
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
</book>
...
try example below
<?php
$xmlStr = file_get_contents('data/books.xml');
$xml = new SimpleXMLElement($xmlStr);
// seach records by tag value:
// find all book records with price higher than 40$
$res = $xml->xpath("book/price[.>'40']/parent::*");
print_r($res);
?>
You will see response like:
Array (
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => bk101
)
[author] => Gambardella, Matthew
[title] => XML Developer's Guide
[genre] => Computer
[price] => 44.95
[publish_date] => 2000-10-01
[description] => An in-depth look at creating applications
with XML.
)
...
Nice xpath tutorial you can find on http://www.zvon.org/xxl/XPathTutorial/General/examples.html
----
Server IP: 64.71.164.2
Probable Submitter: 83.24.145.145
----
Manual Page -- http://www.php.net/manual/en/function.simplexml-element-xpath.php
Edit -- https://master.php.net/note/edit/84196
Del: integrated -- https://master.php.net/note/delete/84196/integrated
Del: useless -- https://master.php.net/note/delete/84196/useless
Del: bad code -- https://master.php.net/note/delete/84196/bad+code
Del: spam -- https://master.php.net/note/delete/84196/spam
Del: non-english -- https://master.php.net/note/delete/84196/non-english
Del: in docs -- https://master.php.net/note/delete/84196/in+docs
Del: other reasons-- https://master.php.net/note/delete/84196
Reject -- https://master.php.net/note/reject/84196
Search -- https://master.php.net/manage/user-notes.php