本文章為你提供一款php xml讀取類,很簡單的一個xml分析類了,它可讀取指它xml文檔,并且輸出或取得指定節點的xml數據,代碼如下:
- <?php
- class dom
- {
- protected $_dom = null;
- public function __construct($xmlfile = '',$ver = '',$encoding = '')
- {
- $this -> _dom = ($ver && $encoding)? new domdocument($ver,$encoding):new domdocument();
- $xml = !$xmlfile?file_get_contents('php://input'):file_get_contents($xmlfile);
- $this -> _dom -> loadxml($xml);
- }
- public function getvalue($nodename)
- {
- $nodes = $this -> _dom -> getelementsbytagname($nodename);
- return null !== $nodes -> item(0)?$nodes -> item(0) -> nodevalue:false;
- }
- } //開源代碼Vevb.com
- //本xml類代碼是利用了php domdocument來解析xml文檔
- ?>
新聞熱點
疑難解答