• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

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

发布: 2007-6-21 15:32 | 作者:   | 来源:   | 查看: 17次 | 进入软件测试论坛讨论

领测软件测试网

   


   文件: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."\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 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://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网