Source for file XML.php
Documentation is available at XML.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Wolfram Kriesing <wolfram@kriesing.de> |
// +----------------------------------------------------------------------+
// $Id: XML.php 320703 2011-12-08 22:08:40Z danielc $
require_once 'XML/Parser.php';
* the XML interface for the tree class
* @var array the first element has to be empty, so we can use
* the parentId=0 as "no parent"
var $data = array (0 => null );
* @var array $parentIdOnLevel
* @var boolean set case folding for the XML_Parser to false
var $folding = false; // turn off case folding
* @var boolean if true it converts all attributes and tag names etc
* to lower case this is default, since i dont see no way
* of case insensitive comparison in the tree class, since
* you can access the internal data directly or you get
* them returned I know this is not 100% proper OOP but that's
* @author Wolfram Kriesing <wolfram@kriesing.de>
* @return boolean true on success
$this->setInput ($handle);
} elseif ($handle != '') {
$this->setInputFile ($handle);
return $this->raiseError ('No filename passed.');
* @author Wolfram Kriesing <wolfram@kriesing.de>
* @return boolean true on success
$this->data[$curId]['id'] = $curId;
$this->data[$curId]['name'] = $this->_toLower?
$this->data[$curId]['attributes'] = $attribs;
$this->data[$curId]['attributes'] = array ();
foreach($attribs as $key => $value) {
// is that a new child, or just a 'next' of a child?
if (isset ($this->data[$elementBeforeId]['level']) &&
$this->level == $this->data[$elementBeforeId]['level']) {
$this->data[$curId]['parentId'] =
$this->data[$elementBeforeId]['parentId'];
// set stuff for the first child !!!
// the root has no parent
$this->data[$curId]['parentId'] = $parentId;
$this->data[$curId]['parentId'] = 0;
* @author Wolfram Kriesing <wolfram@kriesing.de>
* @return boolean true on success
* @author Wolfram Kriesing <wolfram@kriesing.de>
* @return boolean true on success
# QUESTION: why is this method called multiple times for one element?
# is every space a cdata ???
# ANSWER: if you call xml_parse($parser, "foo ", false) and then
# xml_parse($parser, "bar", true), callbacks are done once
# for each xml_parse() call.
#print "cdata = '$cdata'\r\n";
* @author Wolfram Kriesing <wolfram@kriesing.de>
* @return boolean true on success
// $this->data[ sizeof($this->data)-1 ]['cdata'] = $cdata;
// not in use yet :-( is that ok??
* read the data from the xml file and prepare them so the tree
* class can work with it, the preparation is mainly done in startHandler
* @author Wolfram Kriesing <wolfram@kriesing.de>
* @return boolean true on success
* read the data from an xml string and prepare them so the tree
* class can work with it, the preparation is mainly done in startHandler
* @author Wolfram Kriesing <wolfram@kriesing.de>
* @return boolean true on success
$this->parseString ($xmlString, true );
* adds _one_ new element in the tree under the given parent
* the values' keys given have to match the db-columns, because the
* value gets inserted in the db directly
* to add an entire node containing children and so on see 'addNode()'
* @author Wolfram Kriesing <wolfram@kriesing.de>
* @param array this array contains the values that shall be
* inserted in the db-table
* @return mixed either boolean false on failure or the id
/* function add($newValues)
// add the data in the internal structure $this->data
$this->data[sizeof($this->data)] = $newValues;
# i am thinking if it might be a good solution to walk the data-array
# and write each line singlely until the one to add comes, write it and
# keep on writing the data-array
# but that means writing the entire file every time any method that
# changes the xml-file's structure the entire file is written,
# can that not be done somehow better ???
# // and regenerate the xml file
* @author Wolfram Kriesing <wolfram@kriesing.de>
* @param mixed $id the id of the node to be removed
* @return boolean true on success
// remove the data from this->data
# see comment in "add"-method
* move an entry under a given parent or behind a given entry
* @author Wolfram Kriesing <wolfram@kriesing.de>
* @param integer if prevId is given the element with the id idToMove shall be moved _behind_ element with id=prevId
* before would be easier, but then no element could be inserted at the end :-/
* @return boolean true for success
/* function move($idToMove, $newParentId, $prevId=0)
$this->data[$idToMove]['parentId'] = $newParentId;
$this->data[$idToMove]['prevId'] = $prevId;
# see comment in "add"-method
Documentation generated on Mon, 11 Mar 2019 15:47:07 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|