当前位置:首页 > PHP教程 > php类库 > 列表

php读取xml文件的xml实例代码

发布:smiling 来源: PHP粉丝网  添加日期:2014-08-20 15:21:32 浏览: 评论:0 

本文章为你提供一款php xml读取类,很简单的一个xml分析类了,它可读取指它xml文档,并且输出或取得指定节点的xml数据,代码如下:

  1. <?php 
  2. class dom 
  3. { 
  4.   protected $_dom = null; 
  5.    
  6.   public function __construct($xmlfile = '',$ver = '',$encoding = '') 
  7.   { 
  8.     $this -> _dom = ($ver && $encoding)? new domdocument($ver,$encoding):new domdocument(); 
  9.     $xml = !$xmlfile?file_get_contents('php://input'):file_get_contents($xmlfile); 
  10.     $this -> _dom -> loadxml($xml); 
  11.   } 
  12.    
  13.   public function getvalue($nodename) 
  14.   { 
  15.     $nodes = $this -> _dom -> getelementsbytagname($nodename); 
  16.     return null !== $nodes -> item(0)?$nodes -> item(0) -> nodevalue:false; 
  17.   } 
  18. } //开源代码phpfensi.com 
  19.  
  20. //本xml类代码是利用了php domdocument来解析xml文档   
  21. ?> 

Tags: PHP读取xml文件 php读取xml类

分享到: