使用PHP 5.0 轻松解析XML文档(3)

广西双胜奇石

广西双胜奇石

2016-01-29 13:01

使用PHP 5.0 轻松解析XML文档(3),使用PHP 5.0 轻松解析XML文档(3)

文件: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 pachage's 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."rn";     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 pachage's 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);    }}?>      


(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/php/)
展开更多 50%)
分享

猜你喜欢

使用PHP 5.0 轻松解析XML文档(3)

PHP
使用PHP 5.0 轻松解析XML文档(3)

使用PHP 5.0 轻松解析XML文档

PHP
使用PHP 5.0 轻松解析XML文档

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

使用PHP 5.0 轻松解析XML文档(4)

PHP
使用PHP 5.0 轻松解析XML文档(4)

使用PHP 5.0 轻松解析XML文档(5)

PHP
使用PHP 5.0 轻松解析XML文档(5)

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

使用PHP 5.0 轻松解析XML文档(6)

PHP
使用PHP 5.0 轻松解析XML文档(6)

使用PHP 5.0 轻松解析XML文档(2)

PHP
使用PHP 5.0 轻松解析XML文档(2)

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

XMLDOM对象方法:Document对象方法

XMLDOM对象方法:Document对象方法

JSP不是简化的Java

JSP不是简化的Java
下拉加载更多内容 ↓