本文章为你提供一款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;
- }
- }
-
-
- ?>
|