代码如下 | 复制代码 |
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; } } |
//本xml类代码是利用了php domdocument来解析xml文档 ?>