PHP+XML緩衝怎麼快速讀取指定的值

來源:互聯網
上載者:User
PHP+XML緩衝如何快速讀取指定的值
用XML緩衝
結構是

-
-
1
B007

-
2
B001

-
3
B000

-
4
B004

-
5
B003

..............



複製代碼
資料比較多

現在我想快速找到
id=4的pd值
或者id=4下面的item的所有值
應該怎麼寫?

還有一個問題,xml可以支援動態讀取值的嗎?
比如a.xml?id=4
這類型的
可以嗎?謝謝

是PHP的

------解決方案--------------------
參考:http://topic.csdn.net/u/20120521/03/527bc4d2-b4e0-4d6e-9ae4-021a675cfff5.html
------解決方案--------------------
PHP code
$xml=simplexml_load_file('bb.xml');foreach($xml->item as $v){      if($v->id==4) echo "id : $v->id
pd : $v->pd";}
------解決方案--------------------
xpath,還有其他答案嗎。

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;}?> 
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.