⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xml_domit_parser.php

📁 Joomla!是一套获得过多个奖项的内容管理系统(Content Management System, CMS)。Joomla!采用PHP+MySQL数据库开发
💻 PHP
📖 第 1 页 / 共 5 页
字号:
				$this->firstChild =& $child;			}			else {				//remove $child if it already exists				$index = $this->getChildNodeIndex($this->childNodes, $child);				if ($index != -1) {					$this->removeChild($child);				}				//append child				$numNodes = $this->childCount;				//BB: was bug auto-created wrong childnodes[-1]: added IF				if ($numNodes > 0) {					$prevSibling =& $this->childNodes[($numNodes - 1)];				}				$this->childNodes[$numNodes] =& $child;				//set next and previous relationships				//BB: added this line and the else part to finish correcting bug				if (isset( $prevSibling )) {					$child->previousSibling =& $prevSibling;					$prevSibling->nextSibling =& $child;				} else {					unset( $child->previousSibling );					$child->previousSibling = null;					$this->firstChild =& $child;				}			}		}		$this->lastChild =& $child;		$child->parentNode =& $this;		unset($child->nextSibling);		$child->nextSibling = null;		$child->setOwnerDocument($this);		$this->childCount++;		return $child;	} //appendChild	/**	* Inserts a node to the childNodes list of the current node	* @param Object The node to be inserted	* @param Object The node before which the insertion is to occur	* @return Object The inserted node	*/	function &insertBefore(&$newChild, &$refChild) {	    if ($newChild->nodeType == DOMIT_ATTRIBUTE_NODE) {	    	DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,				('Cannot add a node of type ' . get_class($newChild) . ' using insertBefore'));	    }		if (($refChild->nodeType == DOMIT_DOCUMENT_NODE) ||			//($refChild->parentNode->nodeType == DOMIT_DOCUMENT_NODE) ||			($refChild->parentNode == null)) {			DOMIT_DOMException::raiseException(DOMIT_NOT_FOUND_ERR,				 'Reference child not present in the child nodes list.');		}		//if reference child is also the node to be inserted		//leave the document as is and don't raise an exception		if ($refChild->uid == $newChild->uid) {			return $newChild;		}		//if $newChild is a DocumentFragment,		//loop through and insert each node separately		if ($newChild->nodeType == DOMIT_DOCUMENT_FRAGMENT_NODE) {			$total = $newChild->childCount;			for ($i = 0; $i < $total; $i++) {				$currChild =& $newChild->childNodes[$i];				$this->insertBefore($currChild, $refChild);			}			return $newChild;		}		//remove $newChild if it already exists		$index = $this->getChildNodeIndex($this->childNodes, $newChild);		if ($index != -1) {			$this->removeChild($newChild);		}		//find index of $refChild in childNodes		$index = $this->getChildNodeIndex($this->childNodes, $refChild);		if ($index != -1) {			//reset sibling chain			if ($refChild->previousSibling != null) {				$refChild->previousSibling->nextSibling =& $newChild;				$newChild->previousSibling =& $refChild->previousSibling;			}			else {				$this->firstChild =& $newChild;				if ($newChild->previousSibling != null) {					unset($newChild->previousSibling);					$newChild->previousSibling = null;				}			}			$newChild->parentNode =& $refChild->parentNode;			$newChild->nextSibling =& $refChild;			$refChild->previousSibling =& $newChild;			//add node to childNodes			$i = $this->childCount;			while ($i >= 0) {				if ($i > $index) {					$this->childNodes[$i] =& $this->childNodes[($i - 1)];				}				else if ($i == $index) {					$this->childNodes[$i] =& $newChild;				}				$i--;			}			$this->childCount++;		}		else {			$this->appendChild($newChild);		}		$newChild->setOwnerDocument($this);		return $newChild;	} //insertBefore	/**	* Replaces a node with another	* @param Object The new node	* @param Object The old node	* @return Object The new node	*/	function &replaceChild(&$newChild, &$oldChild) {	    if ($newChild->nodeType == DOMIT_ATTRIBUTE_NODE) {	    	DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,				('Cannot add a node of type ' . get_class($newChild) . ' using replaceChild'));	    }		else if ($newChild->nodeType == DOMIT_DOCUMENT_FRAGMENT_NODE) { //if $newChild is a DocumentFragment			//replace the first node then loop through and insert each node separately			$total = $newChild->childCount;			if ($total > 0) {				$newRef =& $newChild->lastChild;				$this->replaceChild($newRef, $oldChild);				for ($i = 0; $i < ($total - 1); $i++) {					$currChild =& $newChild->childNodes[$i];					$this->insertBefore($currChild, $newRef);				}			}			return $newChild;		}		else {			if ($this->hasChildNodes()) {				//remove $newChild if it already exists				$index = $this->getChildNodeIndex($this->childNodes, $newChild);				if ($index != -1) {					$this->removeChild($newChild);				}				//find index of $oldChild in childNodes				$index = $this->getChildNodeIndex($this->childNodes, $oldChild);				if ($index != -1) {					$newChild->ownerDocument =& $oldChild->ownerDocument;					$newChild->parentNode =& $oldChild->parentNode;					//reset sibling chain					if ($oldChild->previousSibling == null) {						unset($newChild->previousSibling);						$newChild->previousSibling = null;					}					else {						$oldChild->previousSibling->nextSibling =& $newChild;						$newChild->previousSibling =& $oldChild->previousSibling;					}					if ($oldChild->nextSibling == null) {						unset($newChild->nextSibling);						$newChild->nextSibling = null;					}					else {						$oldChild->nextSibling->previousSibling =& $newChild;						$newChild->nextSibling =& $oldChild->nextSibling;					}					$this->childNodes[$index] =& $newChild;					if ($index == 0) $this->firstChild =& $newChild;					if ($index == ($this->childCount - 1)) $this->lastChild =& $newChild;					$newChild->setOwnerDocument($this);					return $newChild;				}			}			DOMIT_DOMException::raiseException(DOMIT_NOT_FOUND_ERR,				('Reference node for replaceChild not found.'));		}	} //replaceChild	/**	* Removes a node from the childNodes list of the current node	* @param Object The node to be removed	* @return Object The removed node	*/	function &removeChild(&$oldChild) {		if ($this->hasChildNodes()) {			//find index of $oldChild in childNodes			$index = $this->getChildNodeIndex($this->childNodes, $oldChild);			if ($index != -1) {				//reset sibling chain				if (($oldChild->previousSibling != null) && ($oldChild->nextSibling != null)) {					$oldChild->previousSibling->nextSibling =& $oldChild->nextSibling;					$oldChild->nextSibling->previousSibling =& $oldChild->previousSibling;				}				else if (($oldChild->previousSibling != null) && ($oldChild->nextSibling == null)) {					$this->lastChild =& $oldChild->previousSibling;					unset($oldChild->previousSibling->nextSibling);					$oldChild->previousSibling->nextSibling = null;				}				else if (($oldChild->previousSibling == null) && ($oldChild->nextSibling != null)) {					unset($oldChild->nextSibling->previousSibling);					$oldChild->nextSibling->previousSibling = null;					$this->firstChild =& $oldChild->nextSibling;				}				else if (($oldChild->previousSibling == null) && ($oldChild->nextSibling == null)) {					unset($this->firstChild);					$this->firstChild = null;					unset($this->lastChild);					$this->lastChild = null;				}				$total = $this->childCount;				//remove node from childNodes				for ($i = 0; $i < $total; $i++) {					if ($i == ($total - 1)) {						array_splice($this->childNodes, $i, 1);					}					else if ($i >= $index) {						$this->childNodes[$i] =& $this->childNodes[($i + 1)];					}				}				$this->childCount--;				$oldChild->clearReferences();				return $oldChild;			}		}		DOMIT_DOMException::raiseException(DOMIT_NOT_FOUND_ERR,				('Target node for removeChild not found.'));	} //removeChild	/**	* Searches the element tree for an element with the specified attribute name and value.	* @param string The value of the attribute	* @param string The name of the attribute	* @param boolean True if the first found node is to be returned as a node instead of a nodelist	* @param boolean True if uid is to be considered an attribute	* @return object A NodeList of found elements, or null	*/	function &getElementsByAttribute($attrName = 'id', $attrValue = '',							$returnFirstFoundNode = false, $treatUIDAsAttribute = false) {		require_once(DOMIT_INCLUDE_PATH . 'xml_domit_nodemaps.php');		$nodelist = new DOMIT_NodeList();		switch ($this->nodeType) {			case DOMIT_ELEMENT_NODE:				$this->_getElementsByAttribute($nodelist, $attrName, $attrValue,										$returnFirstFoundNode, $treatUIDAsAttribute);				break;			case DOMIT_DOCUMENT_NODE:				if ($this->documentElement != null) {					$this->documentElement->_getElementsByAttribute($nodelist,							$attrName, $attrValue, $returnFirstFoundNode, $treatUIDAsAttribute);				}				break;		}		if ($returnFirstFoundNode) {			if ($nodelist->getLength() > 0) {				return $nodelist->item(0);			}			else {				$null = null;				return $null;			}		}		else {			return $nodelist;		}	} //getElementsByAttribute	/**	* Searches the element tree for an element with the specified attribute name and value.	* @param object The node list of found elements	* @param string The value of the attribute	* @param string The name of the attribute	* @param boolean True if the first found node is to be returned as a node instead of a nodelist	* @param boolean True if uid is to be considered an attribute	* @param boolean True the node has been found	*/	function _getElementsByAttribute(&$nodelist, $attrName, $attrValue,							$returnFirstFoundNode, $treatUIDAsAttribute, $foundNode = false) {		if (!($foundNode && $returnFirstFoundNode)) {			if (($this->getAttribute($attrName) == $attrValue) ||				($treatUIDAsAttribute && ($attrName == 'uid') && ($this->uid == $attrValue))) {				$nodelist->appendNode($this);				$foundNode = true;				if ($returnFirstFoundNode) return;			}			$total = $this->childCount;			for ($i = 0; $i < $total; $i++) {				$currNode =& $this->childNodes[$i];				if ($currNode->nodeType == DOMIT_ELEMENT_NODE) {					$currNode->_getElementsByAttribute($nodelist,								$attrName, $attrValue, $returnFirstFoundNode,								$treatUIDAsAttribute, $foundNode);				}			}		}	} //_getElementsByAttribute	/**	* Performs an XPath query	* @param string The query pattern	* @return Object A NodeList containing the found nodes	*/	function &selectNodes($pattern, $nodeIndex = 0) {		require_once(DOMIT_INCLUDE_PATH . 'xml_domit_xpath.php');		$xpParser = new DOMIT_XPath();		return $xpParser->parsePattern($this, $pattern, $nodeIndex);	} //selectNodes	/**	* Converts the childNodes array into a NodeList object	* @return Object A NodeList containing elements of the childNodes array	*/	function &childNodesAsNodeList() {		require_once('xml_domit_nodemaps.php');		$myNodeList = new DOMIT_NodeList();		$total = $this->childCount;		for ($i = 0; $i < $total; $i++) {			$myNodeList->appendNode($this->childNodes[$i]);		}		return $myNodeList;	} //childNodesAsNodeList} //DOMIT_ChildNodes_Interface/*** A class representing the DOM Document** @package domit-xmlparser* @subpackage domit-xmlparser-main* @author John Heinstein <johnkarl@nbnet.nb.ca>*/class DOMIT_Document extends DOMIT_ChildNodes_Interface {	/** @var Object The xml declaration processing instruction */	var $xmlDeclaration;	/** @var Object A reference to a DOMIT_DocType object */	var $doctype;	/** @var Object A reference to the root node of the DOM document */	var $documentElement;	/** @var string The parser used to process the DOM document, either "EXPAT" or "SAXY" */	var $parser;	/** @var Object A reference to the DOMIT_DOMImplementation object */	var $implementation;	/** @var boolean True if the DOM document has been modifed since being parsed (NOT YET IMPLEMENTED!) */	var $isModified;	/** @var boolean True if whitespace is to be preserved during parsing */	var $preserveWhitespace = false;	/** @var Array User defined translation table for XML entities; passed to SAXY */	var $definedEntities = array();    /** @var boolean If true, loadXML or parseXML will attempt to detect and repair invalid xml */    var $doResolveErrors = false;    /** @var boolean If true, elements tags will be rendered to string as <element></element> rather than <element/> */    var $doExpandEmptyElementTags = false;	/** @var array A list of exceptions to the empty element expansion rule */	var $expandEmptyElementExceptions = array();    /** @var boolean If true, namespaces will be processed */    var $isNamespaceAware = false;	/** @var int The error code returned by the SAX parser */    var $errorCode = 0;	/** @var string The error string returned by the SAX parser */    var $errorString = '';	/** @var object A reference to a http connection or proxy server, if one is required */    var $httpConnection = null;	/** @var boolean True if php_http_client_generic is to be used instead of PHP get_file_contents to retrieve xml data */	var $doUseHTTPClient = false;	/** @var array An array of namespacesURIs mapped to prefixes */	var $namespaceURIMap = array();	/**	* DOM Document constructor	*/	function DOMIT_Document() {		$this->_constructor();		$this->xmlDeclaration = null;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -