PHP + XML cache how to quickly read the specified value the XML cache structure is & nbsp;-& lt; channel & gt; & nbsp;-& lt; item & gt; & nbsp; & lt; id & gt; 1 & lt; id & gt; & nbsp; & lt; pd & gt; B007 & lt; pd & gt; & nbsp; & lt; item & gt; & PHP + XML cache how to quickly read the specified value
Cache with XML
Structure is
-
-
1
B007
-
2
B001
-
3
B000
-
4
B004
-
5
B003
..............
Large data volume
Now I want to quickly find
Id = 4 pd value
Or all the values of items under id = 4
What should I do?
Another question is, can xml support dynamic reading of values?
For example, a. xml? Id = 4
This type
Yes? Thank you.
Yes for PHP
------ Solution --------------------
Reference: http://topic.csdn.net/u/20120521/03/527bc4d2-b4e0-4d6e-9ae4-021a675cfff5.html
------ Solution --------------------
PHP code
$ Xml = simplexml_load_file ('BB. XML'); foreach ($ xml-> item as $ v) {if ($ v-> id = 4) echo "id: $ v-> id
Pd: $ v-> pd ";}
------ Solution --------------------
Xpath. Are there other answers.
PHP code
[User:root Time:10:28:18 Path:/home/liangdong/php]$ php xpath.php pd B004[User:root Time:10:28:19 Path:/home/liangdong/php]$ cat xpath.php
1
B007
2
B001
3
B000
4
B004
5
B003
EOF;$xml = simplexml_load_string($str, "SimpleXMLElement", LIBXML_NOBLANKS);$res = $xml->xpath("/channel/item/id[text()=4]/parent::item/pd");foreach ($res as $node) { echo $node->getName() . " " . $node->{0} . PHP_EOL;}?>