Easily parse XML documents with PHP 5.0 (3)

Source: Internet
Author: User
XML file: simpledocumentroot.php

<?php/** *========================================================= * * @author Hahawen (older Youth) * @since 2004-12- @copyright Copyright (c), Nxcoder Group * *========================================================= *//** * CL Ass Simpledocumentroot * XML root class, include Values/attributes/subnodes. * All this pachage's is work to 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 '? > Priv Ate $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]);    The Public Function Getnodebyid ($id) {return $this->nodelists[$id]; The Public Function CreateNode ($name, $attributes) {return $this->createnodebyname ($this, $name, $attributes,    -1);    The Public Function Removenode ($name) {return $this->removenodebyname ($this, $name);    The Public Function getnode ($name =null) {return $this->getnodebyname ($this, $name);     The Public Function Getsavexml () {$prefixSpace = ""; $str = $this->prefixstr. "     \ r \ n ";    Return $STR. Parent::getsavexml (0);       }}?>
  
File: simpledocumentnode.php

<?php/** *========================================================= * * @author Hahawen (older Youth) * @since 2004-12- @copyright Copyright (c), Nxcoder Group * *========================================================= *//** * CL Ass Simpledocumentnode * XML Node class, include Values/attributes/subnodes. * All this pachage's is work to 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->getnodeb    Yid ($this->pnodeid);    The Public Function Getseq () {return $this->seq; } public FunctiOn CreateNode ($name, $attributes) {return $this->createnodebyname ($this->rootobject, $name, $attributes, $this-    >getseq ());    The Public Function Removenode ($name) {return $this->removenodebyname ($this->rootobject, $name);    The Public Function getnode ($name =null) {return $this->getnodebyname ($this->rootobject, $name);       }}?>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.