首页 > 语言 > PHP > 正文

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

2024-09-04 11:44:05
字体:大 中 小
来源:转载
供稿:网友

本文章为你提供一款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. } //开源代码Vevb.com 
  19.  
  20. //本xml类代码是利用了php domdocument来解析xml文档   
  21. ?> 

上一篇:PHPMailer邮件类

下一篇:PHP RSS 生成类

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表