[Phpxd-commits] CVS: phpXD/include/dom Attr.php,NONE,1.1 CDataSection.php,NONE,1.1 CharacterData.php
Status: Beta
Brought to you by:
growbal
From: Thomas D. <th...@us...> - 2002-01-25 22:18:21
|
Update of /cvsroot/phpxd/phpXD/include/dom In directory usw-pr-cvs1:/tmp/cvs-serv12964/include/dom Added Files: Attr.php CDataSection.php CharacterData.php Comment.php DOMException.php DOMImplementation.php Document.php DocumentFragment.php DocumentType.php Element.php Entity.php EntityReference.php NamedNodeMap.php Node.php NodeList.php ProcessingInstruction.php Text.php Log Message: --- NEW FILE: Attr.php --- <?php // phpXD - a XML DOM Implementation // // This Software and all associated files are released unter the // GNU Public License (GPL), see LICENSE for details. // // $Id: Attr.php,v 1.1 2002/01/25 22:18:18 thomi Exp $ /** * Class representing the DOM Attr interface. * * @package phpXD * @author Thomas Dohmke <th...@do...> * @version $Revision: 1.1 $ */ class Attr extends Node { /** * The name of the attribute.<br> * DOM-Level 1 * * @private * @type string */ var $name; /** * A link to the Element object that owns this attribute.<br> * DOM-Level 2 * * @private * @type Node */ var $ownerElement; /** * If this attribute was explicity set in the XML source for the parent * element or it is a default value in the DTD (currently not supported by * phpXD) specified is true.<br> * DOM-Level 1 * * @private * @type boolean */ var $specified; /** * The value of the attribute.<br> * DOM-Level 1 * * @private * @type string */ var $value; /** * Constructor of the class. * * @public */ function Attr() { Node::Node(); $this->nodeType = ATTRIBUTE_NODE; $this->specified = true; $this->name =& $this->nodeName; } /** * Returns the name of the attribute.<br> * DOM-Level 1 * * @public * @returns string */ function getName() { return $this->name; } /** * Returns a reference to the owner of the attribute.<br> * DOM-Level 2 * * @public * @returns Node */ function &getOwnerElement() { return $this->ownerElement; } /** * Returns true if the attribute was set explicity in the XML Source or in * the DTD (not supported).<br> * DOM-Level 1 * * @public * @returns boolean */ function getSpecified() { return $this->specified; } /** * Return the value of the attribute.<br> * DOM-Level 1 * * @public * @returns string */ function getValue() { if (isset($this->value)) { return $this->value; } } /** * Sets the value of the attribute<br> * DOM-Level 1 * * @public * @param $value <code>string</code> * @returns void */ function setValue($value) { if (isset($this->childNodes)) { $child =& $this->firstChild; while (isset($child)) { removeChild($child); $child =& $this->firstChild; } } $new = new Text(); $new->nodeValue = $value; $new->ownerDocument =& $this->ownerDocument; $this->firstChild =& $new; $this->lastChild =& $this->firstChild; $this->nodeValue =& $this->firstChild->nodeValue; $this->value =& $this->nodeValue; } /** * Sets the value of the attribute (inherited function from Node interface) * <br>DOM-Level 1 * * @public * @param $nodeValue <code>string</code> * @returns void */ function setNodeValue($nodeValue) { $this->setValue($nodeValue); } /** * This inherited function from Node interface is not supported by the Attr * interface.<br> * DOM-Level 1 * * @public * @returns NOT_SUPPORTED_ERR */ function &appendChild(&$newChild) { return NOT_SUPPORTED_ERR; } /** * This inherited function from Node interface is not supported by the Attr * interface.<br> * DOM-Level 1 * * @public * @returns NOT_SUPPORTED_ERR */ function &insertBefore(&$newChild, &$refChild) { return NOT_SUPPORTED_ERR; } /** * This inherited function from Node interface is not supported by the Attr * interface.<br> * DOM-Level 1 * * @public * @returns NOT_SUPPORTED_ERR */ function &replaceChild($newChild, $oldChild) { return NOT_SUPPORTED_ERR; } } ?> --- NEW FILE: CDataSection.php --- <?php // phpXD - a XML DOM Implementation // // This Software and all associated files are released unter the // GNU Public License (GPL), see LICENSE for details. // // $Id: CDataSection.php,v 1.1 2002/01/25 22:18:18 thomi Exp $ /** * Class representing the DOM CDataSection interface. * * @package phpXD * @author Thomas Dohmke <th...@do...> * @version $Revision: 1.1 $ */ class CDataSection extends Text { /** * Constructor of the class. * * @public */ function CDataSection() { Text::Text(); $this->nodeType = CDATA_SECTION_NODE; $this->nodeName = "#cdata-section"; } } ?> --- NEW FILE: CharacterData.php --- <?php // phpXD - a XML DOM Implementation // // This Software and all associated files are released unter the // GNU Public License (GPL), see LICENSE for details. // // $Id: CharacterData.php,v 1.1 2002/01/25 22:18:18 thomi Exp $ /** * Class representing the DOM CharacterData interface. * * @package phpXD * @author Thomas Dohmke <th...@do...> * @version $Revision: 1.1 $ */ class CharacterData extends Node { /** * The "raw" data of the CharacterData node.<br> * DOM-Level 1 * * @private * @type string */ var $data; /** * The size of the string stored in data.<br> * DOM-Level 1 * * @private * @type int */ var $length; /** * Constructor of the class. * * @public */ function CharacterData() { Node::Node(); $this->data =& $this->nodeValue; } /** * Returns the data stored in this node.<br> * DOM-Level 1 * * @public * @returns string */ function getData() { return $this->data; } /** * Sets the data stored in this node.<br> * DOM-Level 1 * * @public * @param $data <code>string</code> * @returns string */ function setData($data) { $this->nodeValue = $data; } /** * Returns the length of the data stored in this node.<br> * DOM-Level 1 * * @public * @returns string */ function getLength() { return strlen($this->data); } /** * Appends contents of the arg parameter to the current contents of the data * attribute.<br> * DOM-Level 1 * * @public * @param $arg <code>string</code> * @returns string */ function appendData($arg) { $this->nodeValue .= $arg; } /** * Truncates the data attribute; It removes count characters, starting at * the offset position.<br> * DOM-Level 1 * * @public * @param $offset <code>int</code> * @param $count <code>int</code> * @returns string */ function deleteData($offset, $count) { $this->nodeValue = substr($this->nodeValue, 0, $offset-1). substr($this->nodeValue, $offset+count); } /** * Takes a string, splits the data attributes current contents at the given * offset, then inserts the string arg between the two substrings.<br> * DOM-Level 1 * * @public * @param $offset <code>int</code> * @param $arg <code>string</code> * @returns string */ function insertData($offset, $arg) { $this->nodeValue = substr($this->nodeValue, 0, $offset-1).$arg. substr($this->nodeValue, $offset); } /** * Replaces a substring within the data attribute with another string.<br> * DOM-Level 1 * * @public * @param $offset <code>int</code> * @param $count <code>int</code> * @param $arg <code>string</code> * @returns string */ function replaceData($offset, $count, $arg) { if ($offset + $count > strlen($this->nodeValue)) { $count = strlen($this->nodeValue) - $offset; } $this->nodeValue = substr($this->nodeValue, 0, $offset-1). substr($arg, 0, $count) . substr($this->nodeValue, $offset+$count); } /** * Returns a string that contains a subset of the string stored in the data * attribute.<br> * DOM-Level 1 * * @public * @param $offset <code>int</code> * @param $count <code>int</code> * @returns string */ function substringData($offset, $count) { return substr($this->nodeValue, $offset, $count); } } ?> --- NEW FILE: Comment.php --- <?php // phpXD - a XML DOM Implementation // // This Software and all associated files are released unter the // GNU Public License (GPL), see LICENSE for details. // // $Id: Comment.php,v 1.1 2002/01/25 22:18:18 thomi Exp $ /** * Class representing the DOM Comment interface. * * @package phpXD * @author Thomas Dohmke <th...@do...> * @version $Revision: 1.1 $ */ class Comment extends CharacterData { /** * Constructor of the class. * * @public */ function Comment() { CharacterData::CharacterData(); $this->nodeName = "#comment"; $this->nodeType = COMMENT_NODE; } } ?> --- NEW FILE: DOMException.php --- <?php // phpXD - a XML DOM Implementation // // This Software and all associated files are released unter the // GNU Public License (GPL), see LICENSE for details. // // $Id: DOMException.php,v 1.1 2002/01/25 22:18:18 thomi Exp $ /** * Because PHP4 doesn't support exceptions, only the ExceptionCodes are * defined. The Functions which normally would like to raise a exception, * returns one of this ExceptionCodes. * Currently not all ExceptionsCodes are used, only NOT_SUPPORTED_ERR is * really often returned. ;=) */ /** * If index or size is negative, or greater than the allowed value.<br> * DOM-Level 1 * * @const INDEX_SIZE_ERR */ define("INDEX_SIZE_ERR", 1); /** * If the specified range of text does not fit into a DOMString.<br> * DOM-Level 1 * * @const DOMSTRING_SIZE_ERR */ define("DOMSTRING_SIZE_ERR", 2); /** * If any node is inserted somewhere it doesn't belong.<br> * DOM-Level 1 * * @const HIERARCHY_REQUEST_ERR */ define("HIERARCHY_REQUEST_ERR", 3); /** * If a node is used in a different document than the one * that created it (that doesn't support it).<br> * DOM-Level 1 * * @const WRONG_DOCUMENT_ERR */ define("WRONG_DOCUMENT_ERR", 4); /** * If an invalid or illegal character is specified, such as in a name. <br> * DOM-Level 1 * * @const INVALID_CHARACTER_ERR */ define("INVALID_CHARACTER_ERR", 5); /** * If data is specified for a node which does not support data.<br> * DOM-Level 1 * * @const NO_DATA_ALLOWED_ERR */ define("NO_DATA_ALLOWED_ERR", 6); /** * If an attempt is made to modify an object where modifications * are not allowed.<br> * DOM-Level 1 * * @const NO_MODIFICATION_ALLOWED_ERR */ define("NO_MODIFICATION_ALLOWED_ERR", 7); /** * If an attempt is made to reference a node in a context where * it does not exist.<br> * DOM-Level 1 * * @const NOT_FOUND_ERR */ define("NOT_FOUND_ERR", 8); /** * If the implementation does not support the requested type of object * or operation.<br> * DOM-Level 1 * * @const NOT_SUPPORTED_ERR */ define("NOT_SUPPORTED_ERR", 9); /** * If an attempt is made to add an attribute that is already in * use elsewhere.<br> * DOM-Level 1 * * @const INUSE_ATTRIBUTE_ERR */ define("INUSE_ATTRIBUTE_ERR", 10); /** * If an attempt is made to use an object that is not, or is no * longer, usable.<br> * DOM-Level 2 * * @const INVALID_STATE_ERR */ define("INVALID_STATE_ERR", 11); /** * If an invalid or illegal string is specified.<br> * DOM-Level 2 * * @const SYNTAX_ERR */ define("SYNTAX_ERR", 12); /** * If an attempt is made to modify the type of the underlying object.<br> * DOM-Level 2 * * @const INVALID_MODIFICATION_ERR */ define("INVALID_MODIFICATION_ERR", 13); /** * If an attempt is made to create or change an object in a way which * is incorrect with regard to namespaces.<br> * DOM-Level 2 * * @const NAMESPACE_ERR */ define("NAMESPACE_ERR", 14); /** * If a parameter or an operation is not supported by the underlying object.<br> * DOM-Level 2 * * @const INVALID_ACCESS_ERR */ define("INVALID_ACCESS_ERR", 15); ?> --- NEW FILE: DOMImplementation.php --- <?php // phpXD - a XML DOM Implementation // // This Software and all associated files are released unter the // GNU Public License (GPL), see LICENSE for details. // // $Id: DOMImplementation.php,v 1.1 2002/01/25 22:18:18 thomi Exp $ /** * Class representing the DOM DOMImplementation interface. * * @package phpXD * @author Thomas Dohmke <th...@do...> * @version $Revision: 1.1 $ */ class DOMImplementation { /** * Tests to see if the DOM implementation supports a given named feature * package.<br> * DOM-Level 1 * * @public * @param $feature <code>string</code> * @param $version <code>string</code> * @returns boolean */ function hasFeature($feature, $version) { if (($feature == "XML") || ($feature == "Core")) { if ($version == "1.0") { return true; } } return false; } /** * Creates a new, empty Document with the given document type.<br> * DOM-Level 2 * * @public * @param $namespaceURI <code>string</code> * @param $qualifiedName <code>string</code> * @param $doctype <a href="DocumentType.html">DocumentType</a> * @returns Document */ function &createDocument($namespaceURI, $qualifiedName, &$doctype) { if (!(strpos($qualifiedName, ":") === false)) { $prefix = substr($qualifiedName, 0, strpos($qualifiedName, ":")); $localName = substr($qualifiedName, strpos($this->nodeName, ":")+1); if (empty($prefix) || empty($localName)) { return NAMESPACE_ERR; } } else { if (empty($qualifiedName)) { return NAMESPACE_ERR; } } if (empty($namespaceURI)) { return NAMESPACE_ERR; } if (($namespaceURI != "http://www.w3.org/XML/1998/namespace") && ($prefix == "xml")) { return NAMESPACE_ERR; } if (!empty($doctype->ownerDocument)) { return WRONG_DOCUMENT_ERR; } $doc = new Document(); $doc->doctype =& $doctype; $doc->doctype->ownerDocument =& $this; $doc->doctype->namespaceURI = $namespaceURI; $doc->namespaceURI = $namespaceURI; $doc->prefix = $prefix; $doc->localName = $localName; return $doc; } /** * Creates an empty DocumentType node that is not associated with any * document.<br> * DOM-Level 2 * * @public * @param $qualifiedName <code>string</code> * @param $publicId <code>string</code> * @param $systemId <code>string</code> * @returns DocumentType */ function createDocumentType($qualifiedName, $publicId, $systemId) { if (!(strpos($qualifiedName, ":") === false)) { $prefix = substr($qualifiedName, 0, strpos($qualifiedName, ":")); $localName = substr($qualifiedName, strpos($this->nodeName, ":")+1); if (empty($prefix) || empty($localName)) { return NAMESPACE_ERR; } } else { if (empty($qualifiedName)) { return NAMESPACE_ERR; } } $dtd = new DocumentType(); $dtd->publicId = $publicId; $dtd->systemId = $systemId; $dtd->nodeName = $qualifiedName; $dtd->prefix = $prefix; $dtd->localName = $localName; return $dtd; } } ?> --- NEW FILE: Document.php --- <?php // phpXD - a XML DOM Implementation // // This Software and all associated files are released unter the // GNU Public License (GPL), see LICENSE for details. // // $Id: Document.php,v 1.1 2002/01/25 22:18:18 thomi Exp $ /** * Class representing the DOM Document interface. * * @package phpXD * @author Thomas Dohmke <th...@do...> * @version $Revision: 1.1 $ */ class Document extends Node { /** * An instance of the DocumentType interface representing the DTD; If no * DTD was declared in the document, this property is null.<br> * DOM-Level 1 * * @private * @type DocumentType */ var $doctype; /** * Points to the single Element node that is the root of the XML tree.<br> * DOM-Level 1 * * @private * @type Element */ var $documentElement; /** * An reference to the DOMImplementation that is responsible for this * document.<br> * DOM-Level 1 * * @private * @type DOMImplementation */ var $implementation; /** * Constructor of the class.<br> * * @public */ function Document() { Node::Node(); $this->nodeType = DOCUMENT_NODE; $this->nodeName = "#document"; } /** * Returns an reference to the DocumentType object.<br> * DOM-Level 1 * * @public * @returns DocumentType */ function &getDoctype() { return $this->doctype; } /** * Returns an reference to the root element.<br> * DOM-Level 1 * * @public * @returns Element */ function &getDocumentElement() { return $this->documentElement; } /** * Returns an reference to the DOMImplementation object.<br> * DOM-Level 1 * * @public * @returns DOMImplementation */ function &getImplementation() { return $this->implementation; } /** * Creates an Attribute node.<br> * DOM-Level 1 * * @public * @param $name <code>string</code> * @param $value <code>string</code> * @returns Attr */ function &createAttribute($name) { $new = new Attr(); $new->nodeName = $name; $new->ownerElement = NULL; $new->ownerDocument =& $this; return $new; } /** * Creates a CDataSection node.<br> * DOM-Level 1 * * @public * @param $data * @returns CDataSection */ function &createCDataSection($data) { $new = new CDataSection(); $new->nodeValue = $data; $new->ownerDocument = &$this; return $new; } /** * Creates a Comment node.<br> * DOM-Level 1 * * @public * @param $data <code>string</code> * @returns Comment */ function &createComment($data) { $new = new Comment(); $new->nodeValue = $data; $new->ownerDocument = &$this; return $new; } /** * Creates a DocumentFragment node.<br> * DOM-Level 1 * * @public * @returns DocumentFragment */ function &createDocumentFragment() { $new = new DocumentFragment(); return $new; } /** * Creates an Element node.<br> * DOM-Level 1 * * @public * @param $tagName <code>string</code> * @returns Element */ function &createElement($tagName) { $new = new Element(); $new->nodeName = $tagName; $new->ownerDocument = &$this; return $new; } /** * Creates an EntityReference node (not supported yet)<br> * DOM-Level 1 * * @public * @param $name <code>string</code> * @returns EntityReference */ function &createEntityReference($name) { return NOT_SUPPORTED_ERR; } /** * Creates a ProcessingInstruction node.<br> * DOM-Level 1 * * @public * @param $target <code>string</code> * @param $data <code>string</code> * @returns ProcessingInstruction */ function &createProcessingInstruction($target, $data) { $new = new ProcessingInstruction(); $new->nodeValue = $data; $new->nodeName = $target; $new->ownerDocument = &$this; return $new; } /** * Creates a Text node.<br> * DOM-Level 1 * * @public * @param $data <code>string</code> * @returns Text */ function &createTextNode($data) { $new = new Text(); $new->nodeValue = $data; $new->ownerDocument = &$this; return $new; } /** * Returns a NodeList of Element nodes from the current document whose * tagName attribute matches the given tagname.<br> * DOM-Level 1 * * @public * @param $tagName <code>string</code> * @returns NodeList */ function &getElementsByTagName($tagName) { $result = new NodeList(); $this->getElementsByTagNameList($tagName, $this->documentElement, $result); return $result; } /** * Same as createAttribute, but includes support for XML namespaces.<br> * DOM-Level 2 * * @public * @param $namespaceURI <code>string</code> * @param $qualifiedName <code>string</code> * @returns Attr */ function &createAttributeNS($namespaceURI, $qualifiedName) { $prefix = substr($qualifiedName, 0, strpos($qualifiedName, ":")); $localName = substr($qualifiedName, strpos($this->nodeName, ":")+1); if (empty($prefix) || empty($localName)) { return NAMESPACE_ERR; } if (empty($namespaceURI)) { return NAMESPACE_ERR; } if (($namespaceURI != "http://www.w3.org/XML/1998/namespace") && ($prefix == "xml")) { return NAMESPACE_ERR; } if (($this->namespaceURI != "http://www.w3.org/2000/xmlns/") && ($prefix == "xmlns")) { return NAMESPACE_ERR; } if ($this->qualifiedName == "xmlns") { return NAMESPACE_ERR; } $newAttr =& $this->createAttribute($qualifiedName); $newAttr->namespaceURI = $namespaceURI; $newAttr->localName = $localName; $newAttr->prefix = $prefix; return $newAttr; } /** * Same as createElement, but includes support for XML namespaces.<br> * DOM-Level 2 * * @public * @param $namespaceURI <code>string</code> * @param $qualifiedName <code>string</code> * @returns Element */ function &createElementNS($namespaceURI, $qualifiedName) { $prefix = substr($qualifiedName, 0, strpos($qualifiedName, ":")); $localName = substr($qualifiedName, strpos($this->nodeName, ":")+1); if (empty($prefix) || empty($localName)) { return NAMESPACE_ERR; } if (empty($namespaceURI)) { return NAMESPACE_ERR; } if (($namespaceURI != "http://www.w3.org/XML/1998/namespace") && ($prefix == "xml")) { return NAMESPACE_ERR; } $newElem =& $this->createElement($qualifiedName); $newElem->namespaceURI = $namespaceURI; $newElem->localName = $localName; $newElem->prefix = $prefix; return $newElem; } /** * Returns a Element node from the current document whose id attribute * matches the given id.<br> * DOM-Level 2 -- NYI * * @public * @param $elementID <code>string</code> * @returns Element */ function &getElementById($elementID) { // This could not be implemented, as long as the DTD is not parsed. return NOT_SUPPORTED_ERR; } /** * Same as getElementByTagName, but includes support for XML namespaces.<br> * DOM-Level 2 * * @public * @param $namespaceURI <code>string</code> * @param $localName <code>string</code> * @returns NodeList */ function &getElementsByTagNameNS($namespaceURI, $localName) { $result = new NodeList(); $this->getElementsByTagNameNSList($namespaceURI, $localName, $this->documentElement, $result); return $result; } /** * Creates a copy of a Node object from another document that can be * inserted within the current documents node hierarchy.<br> * DOM-Level 2 * * @public * @param $importedNode <a href="Node.html">Node</a> * @param $deep <code>boolean</code> * @returns Node */ function &importNode(&$importedNode, $deep) { if ($importedNode->nodeType == ATTRIBUTE_NODE) { $newNode =& $importedNode->cloneNode(true); $newNode->ownerElement = NULL; $newNode->specified = true; } else { if (($importedNode->nodeType == ELEMENT_NODE) || ($importedNode->nodeType == DOCUMENT_FRAGMENT_NODE) || ($importedNode->nodeType == PROCESSING_INSTRUCTION_NODE) || ($importedNode->nodeType == TEXT_NODE) || ($importedNode->nodeType == CDATA_SECTION_NODE) || ($importedNode->nodeType == COMMENT_NODE)) { $newNode =& $importedNode->cloneNode($deep); } else { return NOT_SUPPORTED_ERR; } } $newNode->ownerDocument =& $this; return $newNode; } /** * Runs recursively through the DOM-Tree and returns a NodeList with all * Element nodes that have the searched tagname. * * @private * @param $tagName <code>string</code> * @param $parent <a href="Node.html">Node</a> * @param $result <a href="NodeList.html">NodeList</a> * @returns void */ function getElementsByTagNameList($tagName, &$parent, &$result) { if ($parent->nodeType == ELEMENT_NODE) { if (($parent->tagName == $tagName) || ($tagName == "*")) { $result->insertNode($parent); } if ($parent->hasChildNodes()) { $this->getElementsByTagNameList($tagName, $parent->firstChild, $result); } } if (isset($parent->nextSibling)) { $this->getElementsByTagNameList($tagName, $parent->nextSibling, $result); } } /** * Runs recursively through the DOM-Tree and returns a NodeList with all * Element nodes that have the searched $namespaceURI and $localName. * * @private * @param $namespaceURI <code>string</code> * @param $localName <code>string</code> * @param $parent <a href="Node.html">Node</a> * @param $result <a href="NodeList.html">NodeList</a> * @returns void */ function getElementsByTagNameNSList($namespaceURI, $localName, &$parent, &$result) { if ($parent->nodeType == ELEMENT_NODE) { if ((($parent->namespaceURI == $namespaceURI) && ($parent->localName == $localName)) || (($namespaceURI == "*") && ($parent->localName == $localName)) || (($parent->namespaceURI == $namespaceURI) && ($localName == "*")) || (($namespaceURI == "*") && ($localName == "*"))) { $result->insertNode($parent); } if ($parent->hasChildNodes()) { $this->getElementsByTagNameNSList($namespaceURI, $localName, $parent->firstChild, $result); } } if (isset($parent->nextSibling)) { $this->getElementsByTagNameNSList($namespaceURI, $localName, $parent->nextSibling, $result); } } } ?> --- NEW FILE: DocumentFragment.php --- <?php // phpXD - a XML DOM Implementation // // This Software and all associated files are released unter the // GNU Public License (GPL), see LICENSE for details. // // $Id: DocumentFragment.php,v 1.1 2002/01/25 22:18:18 thomi Exp $ /** * Class representing the DOM DocumentFragment interface. * * @package phpXD * @author Thomas Dohmke <th...@do...> * @version $Revision: 1.1 $ */ class DocumentFragment extends Node { /** * Constructor of the class. * * @public */ function DocumentFragment() { Node::Node(); $this->nodeType = DOCUMENT_FRAGMENT_NODE; $this->nodeName = "#document-fragment"; } } ?> --- NEW FILE: DocumentType.php --- <?php // phpXD - a XML DOM Implementation // // This Software and all associated files are released unter the // GNU Public License (GPL), see LICENSE for details. // // $Id: DocumentType.php,v 1.1 2002/01/25 22:18:18 thomi Exp $ /** * Class representing the DOM DocumentType interface. * * @package phpXD * @author Thomas Dohmke <th...@do...> * @version $Revision: 1.1 $ */ class DocumentType extends Node { /** * A list of all generall entities declared in the DTD.<br> * DOM-Level 1-- NYI * * @private * @type string */ var $entities; /** * The name of the DTD.<br> * DOM-Level 1 * * @private * @type string */ var $name; /** * Contains a list of XML notation declarations.<br> * DOM-Level 1 -- NYI * * @private * @type string */ var $notations; /** * Contains the documents internat subset as a string value.<br> * DOM-Level 2 * * @private * @type string */ var $internalSubset; /** * The public identifier of the external subset.<br> * DOM-Level 2 * * @private * @type string */ var $publicId; /** * The system identifier of the external subset.<br> * DOM-Level 2 * * @private * @type string */ var $systemId; /** * Constructor of the class.<br> * * @public */ function DocumentType() { Node::Node(); $this->nodeType = DOCUMENT_TYPE_NODE; $this->name =& $this->nodeName; //$notation = new NamedNodeMap(); //$entities = new NamedNodeMap(); } /** * Returns a NamedNodeMap containing all general entities declared in the * DTD.<br> * DOM-Level 1 -- NYI * * @public * @returns NamedNodeMap */ function getEntities() { return NOT_SUPPORTED_ERR; } /** * Returns the internal subset.<br> * DOM-Level 2 * * @public * @returns string */ function getInternalSubset() { return $this->internalSubset; } /** * Returns the name of the DTD.<br> * DOM-Level 1 * * @public * @returns string */ function getName() { return $this->name; } /** * Returns a NamedNodeMap containing all notations declared in the * DTD.<br> * DOM-Level 1 -- NYI * * @public * @returns NamedNodeMap */ function getNotations() { return NOT_SUPPORTED_ERR; } /** * Returns the public identifier of an external subset.<br> * DOM-Level 2 * * @public * @returns string */ function getPublicId() { return $this->publicId; } /** * Returns the system identifier of an external subset.<br> * DOM-Level 2 * * @public * @returns string */ function getSystemId() { return $this->systemId; } } ?> --- NEW FILE: Element.php --- <?php // phpXD - a XML DOM Implementation // // This Software and all associated files are released unter the // GNU Public License (GPL), see LICENSE for details. // // $Id: Element.php,v 1.1 2002/01/25 22:18:18 thomi Exp $ /** * Class representing the DOM Element interface. * * @package phpXD * @author Thomas Dohmke <th...@do...> * @version $Revision: 1.1 $ */ class Element extends Node { /** * The XML tag name.<br> * DOM-Level 1 * * @private * @type string */ var $tagName; /** * Constructor of the class. * * @public */ function Element() { $this->Node(); $this->nodeType = ELEMENT_NODE; $this->tagName =& $this->nodeName; } /** * Returns the XML tag name of the element.<br> * DOM-Level 1 * * @public * @returns string */ function getTagName() { return $this->tagName; } /** * Returns the value of the attribute specified by the name parameter.<br> * DOM-Level 1 * * @public * @param $name <code>string</code> * @returns string */ function getAttribute($name) { $attr =& $this->getAttributeNode($name); return $attr->getValue(); } /** * Returns the attribute specified by the name parameter.<br> * DOM-Level 1 * * @public * @param $name <code>string</code> * @returns Attr */ function &getAttributeNode($name) { if (isset($this->attributes)) { return $this->attributes->getNamedItem($name); } } /** * Returns a NodeList of all child Element nodes whose tagName attribute * matches the give name parameter.<br> * DOM-Level 1 * * @public * @param $name <code>string</code> * @returns NodeList */ function &getElementsByTagName($name) { $result = new NodeList(); $this->getElementsByTagNameList($name, $this->firstChild, $result); return $result; } /** * Removes the Attribute node specified by name.<br> * DOM-Level 1 * * @public * @param $name <code>string</code> * @returns void */ function removeAttribute($name) { if (isset($this->attributes)) { $this->attributes->removeNamedItem($name); } } /** * Removes the specified Attribute node.<br> * DOM-Level 1 * * @public * @param $oldAttr <a href="Attr.html">Attr</a> * @returns Attr */ function &removeAttributeNode(&$oldAttr) { if (isset($this->attributes)) { return $this->attributes->removeNamedItem($oldAttr->nodeName); } } /** * Set the Attribute name to the value. If the node does not exist, it is * created.<br> * DOM-Level 1 * * @public * @param $name string * @param $value string * @returns void */ function setAttribute($name, $value) { $new = new Attr(); $new->nodeName = $name; $new->setValue($value); $new->ownerElement = &$this; $new->ownerDocument = &$this->ownerDocument; if (empty($this->attributes)) { $this->attributes = new NamedNodeMap(); } $this->attributes->setNamedItem($new); } /** * Sets the specified Attribute node.<br> * DOM-Level 1 * * @public * @param $newAttr <a href="Attr.html">Attr</a> * @returns Attr */ function &setAttributeNode(&$newAttr) { if (empty($this->attributes)) { $this->attributes = new NamedNodeMap(); } return $this->attributes->setNamedItem($newAttr); } /** * Same as getAttribute, but includes support for XML namespaces.<br> * DOM-Level 2 * * @public * @param $namespaceURI <code>string</code> * @param $localName <code>string</code> * @returns string */ function getAttributeNS($namespaceURI, $localName) { if (isset($this->attributes)) { $attr =& $this->attributes->getNamedItemNS($namespaceURI, $localName); return $attr->getValue(); } } /** * Same as getAttributeNode, but includes support for XML namespaces.<br> * DOM-Level 2 * * @public * @param $namespaceURI <code>string</code> * @param $localName <code>string</code> * @returns Attr */ function &getAttributeNodeNS($namespaceURI, $localName) { if (isset($this->attributes)) { return $this->attributes->getNamedItemNS($namespaceURI, $localName); } } /** * Same as getElementsByTagName, but includes support for XML namespaces.<br> * DOM-Level 2 * * @public * @param $namespaceURI <code>string</code> * @param $localName <code>string</code> * @returns NodeList */ function &getElementsByTagNameNS($namespaceURI, $localName) { $result = new NodeList(); $this->getElementsByTagNameNSList($namespaceURI, $localName, $this->firstChild, $result); return $result; } /** * Returns true when an attribute with a given name is specified on this * element or has a default value, false otherwise. <br> * DOM-Level 2 * * @public * @param $name <code>string</code> * @returns boolean */ function hasAttribute($name) { if (empty($this->attributes)) { return false; } $attr =& $this->attributes->getNamedItem($name); if (!empty($attr)) { return true; } return false; } /** * Same as hasAttribute, but includes support for XML namespaces.<br> * DOM-Level 2 * * @public * @param $namespaceURI <code>string</code> * @param $localName <code>string</code> * @returns boolean */ function hasAttributeNS($namespaceURI, $localName) { if (empty($this->attributes)) { return false; } $attr =& $this->attributes->getNamedItemNS($namespaceURI, $localName); if (!empty($attr)) { return true; } return false; } /** * Same as removeAttribute, but includes support for XML namespaces.<br> * DOM-Level 2 * * @public * @param $namespaceURI <code>string</code> * @param $localName <code>string</code> * @returns void */ function removeAttributeNS($namespaceURI, $localName) { if (isset($this->attributes)) { $this->attributes->removeNamedItemNS($namespaceURI, $localName); } } /** * Same as setAttribute, but includes support for XML namespaces.<br> * DOM-Level 2 * * @public * @param $namespaceURI <code>string</code> * @param $localName <code>string</code> * @returns void */ function setAttributeNS($namespaceURI, $qualifiedName, $value) { $prefix = substr($qualifiedName, 0, strpos($qualifiedName, ":")); $localName = substr($qualifiedName, strpos($this->nodeName, ":")+1); if (empty($prefix) || empty($localName)) { return NAMESPACE_ERR; } if (empty($namespaceURI)) { return NAMESPACE_ERR; } if (($namespaceURI != "http://www.w3.org/XML/1998/namespace") && ($prefix == "xml")) { return NAMESPACE_ERR; } if (($this->namespaceURI != "http://www.w3.org/2000/xmlns/") && ($prefix == "xmlns")) { return NAMESPACE_ERR; } if ($this->qualifiedName == "xmlns") { return NAMESPACE_ERR; } $new = new Attr(); $new->nodeName = $qualifiedName; $new->prefix = $prefix; $new->localName = $localName; $new->setValue($value); $new->ownerElement = &$this; $new->ownerDocument = &$this->ownerDocument; if (empty($this->attributes)) { $this->attributes = new NamedNodeMap(); } $this->attributes->setNamedItemNS($new); } /** * Same as setAttributeNode, but includes support for XML namespaces.<br> * DOM-Level 2 * * @public * @param $newAttr <a href="Attr.html">Attr</a> * @returns Attr */ function setAttributeNodeNS(&$newAttr) { if (empty($this->attributes)) { $this->attributes = new NamedNodeMap(); } return $this->attributes->setNamedItemNS($newAttr); } /** * Runs recursively through the DOM-Tree and returns a NodeList with all * Element nodes that have the searched tagname. * * @private * @param $tagName <code>string</code> * @param $parent <a href="Node.html">Node</a> * @param $result <a href="NodeList.html">NodeList</a> * @returns void */ function getElementsByTagNameList($tagName, &$parent, &$result) { if ($parent->nodeType == ELEMENT_NODE) { if (($parent->tagName == $tagName) || ($tagName == "*")) { $result->insertNode($parent); } if ($parent->hasChildNodes()) { $this->getElementsByTagNameList($tagName, $parent->firstChild, $result); } } if (isset($parent->nextSibling)) { $this->getElementsByTagNameList($tagName, $parent->nextSibling, $result); } } /** * Runs recursively through the DOM-Tree and returns a NodeList with all * Element nodes that have the searched $namespaceURI and $localName. * * @private * @param $namespaceURI <code>string</code> * @param $localName <code>string</code> * @param $parent <a href="Node.html">Node</a> * @param $result <a href="NodeList.html">NodeList</a> * @returns void */ function getElementsByTagNameNSList($namespaceURI, $localName, &$parent, &$result) { if ($parent->nodeType == ELEMENT_NODE) { if ((($parent->namespaceURI == $namespaceURI) && ($parent->localName == $localName)) || (($namespaceURI == "*") && ($parent->localName == $localName)) || (($parent->namespaceURI == $namespaceURI) && ($localName == "*")) || (($namespaceURI == "*") && ($localName == "*"))) { $result->insertNode($parent); } if ($parent->hasChildNodes()) { $this->getElementsByTagNameNSList($namespaceURI, $localName, $parent->firstChild, $result); } } if (isset($parent->nextSibling)) { $this->getElementsByTagNameNSList($namespaceURI, $localName, $parent->nextSibling, $result); } } } ?> --- NEW FILE: Entity.php --- <?php // phpXD - a XML DOM Implementation // // This Software and all associated files are released unter the // GNU Public License (GPL), see LICENSE for details. // // $Id: Entity.php,v 1.1 2002/01/25 22:18:18 thomi Exp $ /** * Class representing the DOM Entity interface. Not supported yet. * * @package phpXD * @author Thomas Dohmke <th...@do...> * @version $Revision: 1.1 $ */ class Entity extends Node { // Sorry, not supported yet! } ?> --- NEW FILE: EntityReference.php --- <?php // phpXD - a XML DOM Implementation // // This Software and all associated files are released unter the // GNU Public License (GPL), see LICENSE for details. // // $Id: EntityReference.php,v 1.1 2002/01/25 22:18:18 thomi Exp $ /** * Class representing the DOM EntityReference interface. Not supported yet. * * @package phpXD * @author Thomas Dohmke <th...@do...> * @version $Revision: 1.1 $ */ class EntityReference extends Node { // Sorry, not supported yet. } ?> --- NEW FILE: NamedNodeMap.php --- <?php // phpXD - a XML DOM Implementation // // This Software and all associated files are released unter the // GNU Public License (GPL), see LICENSE for details. // // $Id: NamedNodeMap.php,v 1.1 2002/01/25 22:18:18 thomi Exp $ /** * Class representing the DOM NamedNodeMap interface * * @package phpXD * @author Thomas Dohmke <th...@do...> * @version $Revision: 1.1 $ */ class NamedNodeMap { /** * Contains all items of tbe NamedNodeMap.<br> * * @private * @type array */ var $nodes; /** * The number of nodes in this map.<br> * DOM-Level 1 * * @private * @type int */ var $length = 0; /** * Returns the number of nodes in the map.<br> * DOM-Level 1 * * @public * @returns int */ function getLength() { return $this->length; } /** * Retrieves a node specified by name<br> * DOM-Level 1 * * @public * @param $name <code>string</code> * @returns Node */ function &getNamedItem($name) { return $this->nodes[$name]; } /** * Returns the indexth item in this map.<br> * DOM-Level 1 * * @public * @param $index <code>int</code> * @returns Node */ function &item($index) { $count = 0; reset($this->nodes); while (list($key, $value) = each($this->nodes)) { if ($count == $index) { return $this->nodes[$key]; } $count++; } return null; } /** * Removes a node specified by name.<br> * DOM-Level 1 * * @public * @param $name <code>string</code> * @returns Node */ function &removeNamedItem($name) { if (isset($this->nodes[$name])) { $removed =& $this->nodes[$name]; unset($this->nodes[$name]); $this->length--; return $removed; } else { return NOT_FOUND_ERR; } } /** * Adds a node using its nodeName attribute.<br> * DOM-Level 1 * * @public * @param $arg <a href="Node.html">Node</a> * @returns Node */ function &setNamedItem(&$arg) { if (!isset($this->nodes[$arg->nodeName])) { $this->length++; $save = null; } else { $save =& $this->nodes[$arg->nodeName]; } $this->nodes[$arg->nodeName] =& $arg; return $save; } /** * Retrieves a node specified by local name and namespace URI.<br> * DOM-Level 2 * * @public * @param $namespaceURI <code>string</code> * @param $localName <code>string</code> * @returns Node */ function &getNamedItemNS($namespaceURI, $localName) { return $this->getNamedItem($namespaceURI.":".$localName); } /** * Removes a node specified by local name and namespace URI.<br> * DOM-Level 2 * * @public * @param $namespaceURI <code>string</code> * @param $localName <code>string</code> * @returns Node */ function &removeNamedItemNS($namespaceURI, $localName) { return $this->removeNamedItem($namespaceURI.":".$localName); } /** * Adds a node using its $namespaceURI and $localName<br> * DOM-Level 2 * * @public * @param $arg <a href="Node.html">Node</a> * @returns Node */ function &setNamedItemNS(&$arg) { if (!isset($this->nodes[$arg->namespaceURI.":".$arg->localName])) { $this->length++; $save = null; } else { $save =& $this->nodes[$arg->namespaceURI.":".$arg->localName]; } $this->nodes[$arg->namespaceURI.":".$arg->localName] =& $arg; return $save; } } ?> --- NEW FILE: Node.php --- <?php // phpXD - a XML DOM Implementation // // This Software and all associated files are released unter the // GNU Public License (GPL), see LICENSE for details. // // $Id: Node.php,v 1.1 2002/01/25 22:18:18 thomi Exp $ /** * @const ELEMENT_NODE */ define("ELEMENT_NODE", 1); /** * @const ATTRIBUTE_NODE */ define("ATTRIBUTE_NODE", 2); /** * @const TEXT_NODE */ define("TEXT_NODE", 3); /** * @const CDATA_SECTION_NODE */ define("CDATA_SECTION_NODE", 4); /** * @const ENTITY_REFERENCE_NODE */ define("ENTITY_REFERENCE_NODE", 5); /** * @const ENTITY_NODE */ define("ENTITY_NODE", 6); /** * @const PROCESSING_INSTRUCTION_NODE */ define("PROCESSING_INSTRUCTION_NODE", 7); /** * @const COMMENT_NODE */ define("COMMENT_NODE", 8); /** * @const DOCUMENT_NODE */ define("DOCUMENT_NODE", 9); /** * @const DOCUMENT_TYPE_NODE */ define("DOCUMENT_TYPE_NODE", 10); /** * @const DOCUMENT_FRAGMENT_NODE */ define("DOCUMENT_FRAGMENT_NODE", 11); /** * @const NOTATION_NODE */ define("NOTATION_NODE", 12); /** * Class representing the DOM Node interface * * @package phpXD * @author Thomas Dohmke <th...@do...> * @version $Revision: 1.1 $ */ class Node { /** * MD5-Hash to compare two nodes. * * This ID is necessary to compare two nodes, because the operator == * is not implemented for objects/references in PHP4. * * @private * @type string */ var $nodeID; /** * Provides access to a list of Attr objects in a NamedNodeMap.<br> * DOM-Level 1 * * @private * @type NamedNodeMap */ var $attributes; /** * A NodeList containing a reference to every child in this Node.<br> * DOM-Level 1 * * @private * @type NodeList */ var $childNodes; /** * Points to the head of the linked list of children in this node.<br> * DOM-Level 1 * * @private * @type Node */ var $firstChild; /** * Points to the end of the linked list of children in the node.<br> * DOM-Level 1 * * @private * @type Node */ var $lastChild; /** * Points to the next Node in the siblings list.<br> * DOM-Level 1 * * @private * @type Node */ var $nextSibling; /** * Depending on the object type (nodeType), this attribute may map to * another attribute of the object or a constant string.<br> * DOM-Level 1 * * @private * @type string */ var $nodeName; /** * Contains a value that indicates the true type of the Node.<br> * DOM-Level 1 * * @private * @type int */ var $nodeType; /** * Depending on the nodeType, this attribute contains null or the * content/value of the node.<br> * DOM-Level 1 * * @private * @type string */ var $nodeValue; /** * Points to the Document used to create this Node object.<br> * DOM-Level 1 * * @private * @type Document */ var $ownerDocument; /** * Points to the parent of this node.<br> * DOM-Level 1 * * @private * @type Node */ var $parentNode; /** * Points to the previous Node in the siblings list.<br> * DOM-Level 1 * * @private * @type Node */ var $previousSibling; /** * Contains the local part of the fully qualified node name.<br> * DOM-Level 2 * * @private * @type string */ var $localName; /** * The namespace URI given to this Node object at creation time, null * if no namespace was given.<br> * DOM-Level 2 * * @private * @type string */ var $namespaceURI; /** * The namespace prefix of this Node, used for nodes that support namespace * prefixes.<br> * DOM-Level 2 * * @private * @type string */ var $prefix; /** * Constructor of the class. * * @public */ function Node() { $this->nodeID = microtime()." ".rand(); } /** * Provides access to a list of Attr objects in a NamedNodeMap.<br> * DOM-Level 1 * * @public * @returns NamedNodeMap */ function &getAttributes() { return $this->attributes; } /** * Returns a NodeList containing a reference to every child in this Node.<br> * DOM-Level 1 * * @public * @returns NodeList */ function &getChildNodes() { return $this->childNodes; } /** * Returns a reference to the head of the linked list of children * in this node.<br> * DOM-Level 1 * * @public * @returns Node */ function &getFirstChild() { return $this->firstChild; } /** * Returns a reference to the end of the linked list of children * in this node.<br> * DOM-Level 1 * * @public * @returns Node */ function &getLastChild() { return $this->lastChild; } /** * Returns a reference to the next node in the siblings list.<br> * DOM-Level 1 * * @public * @returns Node */ function &getNextSibling() { return $this->nextSibling; } /** * Returns the name of the node or null if the node has no name.<br> * DOM-Level 1 * * @public * @returns string */ function getNodeName() { return $this->nodeName; } /** * Returns the type of the node.<br> * DOM-Level 1 * * @public * @returns int */ function getNodeType() { return $this->nodeType; } /** * Returns the value of the node or null if the node has no value.<br> * DOM-Level 1 * * @public * @returns string */ function getNodeValue() { return $this->nodeValue; } /** * Sets the value of this node.<br> * DOM-Level 1 * * @public * @param $nodeValue <code>string</code> * @returns void */ function setNodeValue($nodeValue) { if (($this->nodeType == ELEMENT_NODE) || ($this->nodeType == ENTITY_REFERENCE_NODE) || ($this->nodeType == ENTITY_NODE) || ($this->nodeType == DOCUMENT_NODE) || ($this->nodeType == DOCUMENT_TYPE_NODE) || ($this->nodeType == DOCUMENT_FRAGMENT_NODE) || ($this->nodeType == NOTATION)) { return NO_MODIFICATION_ALLOWED_ERR; } $this->nodeValue = $nodeValue; return null; } /** * Returns a reference to the Document used to create this node.<br> * DOM-Level 1 * * @public * @returns Document */ function &getOwnerDocument() { return $this->ownerDocument; } /** * Returns the parent of this node.<br> * DOM-Level 1 * * @public * @returns Node */ function &getParentNode() { return $this->parentNode; } /** * Returns the previous node in the siblings list.<br> * DOM-Level 1 * * @public * @returns Node */ function &getPreviousSibling() { return $this->previousSibling; } /** * Appends the $newChild node to the end of the child list if the node is * a permitted child of this node.<br> * DOM-Level 1 * * @public * @param $newChild <a href="Node.html">Node</a> * @returns Node */ function &appendChild(&$newChild) { if (($newChild->nodeType == DOCUMENT_FRAGMENT_NODE) && ($this->nodeType != DOCUMENT_FRAGMENT_NODE)) { for ($i = 0; $i < $newChild->childNodes->getLength(); $i++) { $save = &$this->appendChild($newChild->childNodes->item($i)); } return $save; } $check = $this->checkHierarchy($newChild); if ($check > 0) { return $check; } $check = $this->checkDocument($newChild); if ($check > 0) { return $check; } if (isset($newChild->parentNode)) { $result = $newChild->parentNode->removeChild($newChild); } $newChild->parentNode = &$this; $newChild->ownerDocument = &$this->ownerDocument; unset($newChild->nextSibling); unset($newChild->previousSibling); if (!isset($this->firstChild)) { $this->firstChild = &$newChild; $this->lastChild = &$newChild; $this->childNodes = new NodeList(); } else { $this->lastChild->nextSibling = &$newChild; $newChild->previousSibling = &$this->lastChild; $this->lastChild = &$newChild; } $this->childNodes->insertNode($newChild); return $newChild; } /** * Returns a copy of the node without the parent node; If $deep is true, * all children are also copied.<br> * DOM-Level 1 * * @public * @param $deep <code>boolean</code> * @returns Node */ function &cloneNode($deep) { $clone = $this; $clone->Node(); unset($clone->attributes); unset($clone->childNodes); unset($clone->firstChild); unset($clone->lastChild); unset($clone->nextSibling); unset($clone->parentNode); unset($clone->previousSibling); if (isset($this->attributes)) { $clone->attributes = new NamedNodeMap(); unset($oldAttr); for ($i = 0; $i < $this->attributes->getLength(); $i++) { $attr =& $this->attributes->item($i); $newAttr[$i] =& $attr->cloneNode(true); $newAttr[$i]->specified = true; if (!isset($oldAttr)) { $clone->firstAttr = &$newAttr[$i]; } else { $oldAttr->nextSibling = &$newAttr[$i]; $newAttr[$i]->previousSibling = &$oldAttr; } $clone->attributes->setNamedItem($newAttr[$i]); $oldAttr = &$newAttr[$i]; } $clone->lastAttr = &$oldAttr; } if ($deep) { if (isset($this->childNodes)) { $clone->childNodes = new NodeList(); $oldChild = null; for ($i = 0; $i < $this->childNodes->getLength(); $i++) { $child =& $this->childNodes->item($i); $newChild[$i] =& $child->cloneNode($deep); if (!isset($oldChild)) { $clone->firstChild = &$newChild[$i]; } else { $oldChild->nextSibling = &$newChild[$i]; $newChild[$i]->previousSibling = &$oldChild; } $clone->childNodes->insertNode($newChild[$i]); $oldChild = &$newChild[$i]; } $clone->lastChild = &$oldChild; } } return $clone; } /** * This method provides a quick way to check if a node has children.<br> * DOM-Level 1 * * @public * @returns boolean */ function hasChildNodes() { if (isset($this->firstChild)) { return true; } return false; } /** * Inserts the Node object $newChild into the child list of the parent node; * The $refChild parameter allows you to specify where to insert the new * node; If $refChild is null, newChild is inserted at the end of the child * list; If $newChild is linked into the document tree, it is removed before * it is inserted in its new position.<br> * DOM-Level 1 * * @public * @param $newChild <a href="Node.html">Node</a> * @param $refChild <a href="Node.html">Node</a> * @returns Node */ function &insertBefore(&$newChild, &$refChild) { if (($newChild->nodeType == DOCUMENT_FRAGMENT_NODE) && ($this->nodeType != DOCUMENT_FRAGMENT_NODE)) { for ($i = 0; $i < $newChild->childNodes->getLength(); $i++) { $save = &$this->insertBefore($newChild->childNodes->item($i), $refChild); } return $save; } $check = $this->checkHierarchy($newChild); if ($check > 0) { return $check; } $check = $this->checkDocument($newChild); if ($check > 0) { return $check; } if (isset($newChild->parentNode)) { $result = $newChild->parentNode->removeChild($newChild); } $newChild->parentNode = &$this; $newChild->ownerDocument = &$this->ownerDocument; unset($newChild->nextSibling); unset($newChild->previousSibling); if (isset($this->childNodes)) { for ($i = 0; $i < $this->childNodes->getLength(); $i++) { $child =& $this->childNodes->item($i); if ($child->nodeID == $refChild->nodeID && !$inserted) { if ($i > 0) { $prevChild = &$this->childNodes->item($i-1); $prevChild->nextSibling = &$newChild; $newChild->previousSibling = &$prevChild; } else { $this->firstChild = &$newChild; } $newChild->nextSibling = &$child; $child->previousSibling = &$newChild; $this->childNodes->insertNode($newChild, $i); return $newChild; } } } else { $this->firstChild = &$newChild; $this->lastChild = &$this->firstChild; $this->childNodes = new NodeList(); $this->childNodes->insertNode($newChild); return $newChild; } if (!isset($refChild)) { $this->lastChild->nextSibling = &$newChild; $newChild->previousSibling = &$this->lastChild; $this->lastChild = &$newChild; $this->childNodes->insertNode($newChild); return $newChild; } else { return NOT_FOUND_ERR; } } /** * Unlinks the $oldChild node from the child list.<br> * DOM-Level 1 * * @public * @param $oldChild <a href="Node.html">Node</a> * @returns Node */ function &removeChild($oldChild) { if (isset($this->childNodes)) { for ($i = 0; $i < $this->childNodes->getLength(); $i++) { $child =& $this->childNodes->item($i); if ($child->nodeID == $oldChild->nodeID) { if ($i > 0) { $prevChild = &$this->childNodes->item($i-1); $prevChild->nextSibling = &$child->nextSibling; if (isset($child->nextSibling)) { $child->nextSibling->previousSibling = &$prevChild; } else { $this->lastChild = &$prevChild; } } else { $this->firstChild = &$child->nextSibling; } $removedNode = &$this->childNodes->nodes[$i]; $this->childNodes->removeNode($i); return $removedNode; } } } return NOT_FOUND_ERR; } /** * Replaces the child node $oldChild with $newChild; If $newChild is linked * into the document tree, it is removed before the replace is performed.<br> * DOM-Level 1 * * @public * @param $newChild <a href="Node.html">Node</a> * @param $oldChild <a href="Node.html">Node</a> * @returns Node */ function &replaceChild($newChild, $oldChild) { if (($newChild->nodeType == DOCUMENT_FRAGMENT_NODE) && ($this->nodeType != DOCUMENT_FRAGMENT_NODE)) { for ($i = 0; $i < $newChild->childNodes->getLength(); $i++) { $save = &$this->insertBefore($newChild->childNodes->item($i), $oldChild); } return $this->removeChild($oldChild); } $check = $this->checkHierarchy($newChild); if ($check > 0) { return $check; } $check = $this->checkDocument($newChild); if ($check > 0) { return $check; } if (isset($newChild->parentNode)) { $result = $newChild->parentNode->removeChild($newChild); } $newChild->parentNode = &$this; $newChild->ownerDocument = &$this->ownerDocument; if (isset($this->childNodes)) { for ($i = 0; $i < $this->childNodes->getLength(); $i++) { $child =& $this->childNodes->item($i); if ($child->nodeID == $oldChild->nodeID) { if ($i > 0) { $prevChild = &$this->childNodes->item($i-1); $prevChild->nextSibling = &$newChild; } else { $this->firstChild = &$newChild; } $newChild->nextSibling = &$child->nextSibling; $newChild->previousSibling = &$child->previousSibling; if (isset($newChild->nextSibling)) { $newChild->nextSibling->previousSibling = &$newChild; } else { $this->lastChild = &$newChild; } $this->childNodes->replaceNode($newChild, $i); return $oldChild; } } } return NOT_FOUND_ERR; } /** * Returns the local part of the fully qualified node name.<br> * DOM-Level 2 * * @public * @returns string */ function getLocalName() { return $this->localName; } /** * Returns the namespace URI of this node.<br> * DOM-Level 2 * * @public * @returns string */ fun... [truncated message content] |