欢迎光临
我们一直在努力

使用PHP 5.0 轻松解析XML文档(3)-PHP教程,PHP应用

建站超值云服务器,限时71元/月

文件:simpledocumentroot.php

<?php
/**
 *=========================================================
 *
 * @author     hahawen(大龄青年)  
 * @since      2004-12-04
 * @copyright  copyright (c) 2004, nxcoder group
 *
 *=========================================================
 */
/**
 * class simpledocumentroot
 * xml root class, include values/attributes/subnodes.
 * all this pachages is work for xml file, and method is action as dom.
 *
 * @package smartweb.common.xml
 * @version 1.0
 */
class simpledocumentroot extends simpledocumentbase
{
 private $prefixstr = <?xml version="1.0" encoding="utf-8" ?>;
 private $nodelists = array();
 function __construct($nodetag)
 {
        parent::__construct($nodetag);
 }
    public function createnodeobject($pnodeid, $name, $attributes)
    {
     $seq = sizeof($this->nodelists);
     $tmpobject = new simpledocumentnode($this, $pnodeid, $name, $seq);
     $tmpobject->setattributes($attributes);
     $this->nodelists[$seq] = $tmpobject;
     return $tmpobject;
    }
    public function removenodebyid($id)
    {
        if(sizeof($this->nodelists)==1)
            $this->nodelists = array();
     else
      unset($this->nodelists[$id]);
    }
    public function getnodebyid($id)
    {
     return $this->nodelists[$id];
    }
    public function createnode($name, $attributes)
    {
        return $this->createnodebyname($this, $name, $attributes, -1);
    }
    public function removenode($name)
    {
        return $this->removenodebyname($this, $name);
    }
    public function getnode($name=null)
    {
        return $this->getnodebyname($this, $name);
    }
    public function getsavexml()
    {
     $prefixspace = "";
     $str = $this->prefixstr."\r\n";
     return $str.parent::getsavexml(0);
    }
}
?>
      

  
  文件:simpledocumentnode.php

<?php
/**
 *=========================================================
 *
 * @author     hahawen(大龄青年)  
 * @since      2004-12-04
 * @copyright  copyright (c) 2004, nxcoder group
 *
 *=========================================================
 */
/**
 * class simpledocumentnode
 * xml node class, include values/attributes/subnodes.
 * all this pachages is work for xml file, and method is action as dom.
 *
 * @package smartweb.common.xml
 * @version 1.0
 */
class simpledocumentnode extends simpledocumentbase
{
 private $seq = null;
 private $rootobject = null;
    private $pnodeid = null;
    function __construct($rootobject, $pnodeid, $nodetag, $seq)
    {
     parent::__construct($nodetag);
        $this->rootobject = $rootobject;
        $this->pnodeid = $pnodeid;
        $this->seq = $seq;
    }
    public function getpnodeobject()
    {
     return ($this->pnodeid==-1)? $this->rootobject: $this->rootobject->getnodebyid($this->pnodeid);
    }
    public function getseq(){
     return $this->seq;
    }
    public function createnode($name, $attributes)
    {
        return $this->createnodebyname($this->rootobject, $name, $attributes, $this->getseq());
    }
    public function removenode($name)
    {
        return $this->removenodebyname($this->rootobject, $name);
    }
    public function getnode($name=null)
    {
        return $this->getnodebyname($this->rootobject, $name);
    }
}
?>
      
赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 使用PHP 5.0 轻松解析XML文档(3)-PHP教程,PHP应用
分享到: 更多 (0)