VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > PHP >
  • php读取xml文件的xml实例代码

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

出处:http://www.phpfensi.com/php/20140820/4560.html


相关教程