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

📄 xml_domit_lite_parser.php

📁 Joomla!是一套获得过多个奖项的内容管理系统(Content Management System, CMS)。Joomla!采用PHP+MySQL数据库开发
💻 PHP
📖 第 1 页 / 共 4 页
字号:
				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);			}            $null = null;			return $null;		}		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} //DOMIT_Lite_ChildNodes_Interface/*** A class representing the DOM Document** @package domit-xmlparser* @subpackage domit-xmlparser-lite* @author John Heinstein <johnkarl@nbnet.nb.ca>*/class DOMIT_Lite_Document extends DOMIT_Lite_ChildNodes_Interface {	/** @var string The xml declaration text */	var $xmlDeclaration;	/** @var string The doctype text */	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_LITE" */	var $parser;	/** @var Object A reference to the DOMIT_DOMImplementation object */	var $implementation;	/** @var Array User defined translation table for XML entities */	var $definedEntities = array();    /** @var boolean If true, loadXML or parseXML will attempt to detect and repair invalid xml */    var $doResolveErrors = false;	/** @var boolean True if whitespace is to be preserved during parsing */	var $preserveWhitespace = 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 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;	/**	* DOM Document constructor	*/	function DOMIT_Lite_Document() {		$this->_constructor();		$this->xmlDeclaration = '';		$this->doctype = '';		$this->documentElement = null;		$this->nodeType = DOMIT_DOCUMENT_NODE;		$this->nodeName = '#document';		$this->ownerDocument =& $this;		$this->parser = '';		$this->implementation = new DOMIT_DOMImplementation();	} //DOMIT_Lite_Document	/**	* Specifies whether DOMIT! Lite will try to fix invalid XML before parsing begins	* @param boolean True if errors are to be resolved	*/	function resolveErrors($truthVal) {	    $this->doResolveErrors = $truthVal;	} //resolveErrors	/**	* Specifies the parameters of the http conection used to obtain the xml data	* @param string The ip address or domain name of the connection	* @param string The path of the connection	* @param int The port that the connection is listening on	* @param int The timeout value for the connection	* @param string The user name, if authentication is required	* @param string The password, if authentication is required	*/	function setConnection($host, $path = '/', $port = 80, $timeout = 0, $user = null, $password = null) {	    require_once(DOMIT_INCLUDE_PATH . 'php_http_client_generic.php');		$this->httpConnection = new php_http_client_generic($host, $path, $port, $timeout, $user, $password);	} //setConnection	/**	* Specifies whether DOMIT! preserves whitespace when parsing	* @param boolean True if whitespace is to be preserved	*/	function preserveWhitespace($truthVal) {	    $this->preserveWhitespace = $truthVal;	} //preserveWhitespace	/**	* Specifies basic authentication for an http connection	* @param string The user name	* @param string The password	*/	function setAuthorization($user, $password) {		$this->httpConnection->setAuthorization($user, $password);	} //setAuthorization	/**	* Specifies that a proxy is to be used to obtain the xml data	* @param string The ip address or domain name of the proxy	* @param string The path to the proxy	* @param int The port that the proxy is listening on	* @param int The timeout value for the connection	* @param string The user name, if authentication is required	* @param string The password, if authentication is required	*/	function setProxyConnection($host, $path = '/', $port = 80, $timeout = 0, $user = null, $password = null) {	    require_once(DOMIT_INCLUDE_PATH . 'php_http_proxy.php');		$this->httpConnection = new php_http_proxy($host, $path, $port, $timeout, $user, $password);	} //setProxyConnection	/**	* Specifies basic authentication for the proxy	* @param string The user name	* @param string The password	*/	function setProxyAuthorization($user, $password) {		$this->httpConnection->setProxyAuthorization($user, $password);	} //setProxyAuthorization	/**	* Specifies whether an HTTP client should be used to establish a connection	* @param boolean True if an HTTP client is to be used to establish the connection	*/	function useHTTPClient($truthVal) {		$this->doUseHTTPClient = $truthVal;	} //useHTTPClient	/**	* Returns the error code from the underlying SAX parser	* @return int The error code	*/	function getErrorCode() {	    return $this->errorCode;	} //getErrorCode	/**	* Returns the error string from the underlying SAX parser	* @return string The error string	*/	function getErrorString() {	    return $this->errorString;	} //getErrorString	/**	* Specifies whether elements tags will be rendered to string as <element></element> rather than <element/>	* @param boolean True if the expanded form is to be used	* @param mixed An array of tag names that should be excepted from expandEmptyElements rule (optional)	*/	function expandEmptyElementTags($truthVal, $expandEmptyElementExceptions = false) {		$this->doExpandEmptyElementTags = $truthVal;		if (is_array($expandEmptyElementExceptions)) {			$this->expandEmptyElementExceptions = $expandEmptyElementExceptions;		}	} //expandEmptyElementTags	/**	* Set the specified node as document element	* @param Object The node that is to become document element	* @return Object The new document element	*/	function &setDocumentElement(&$node) {		if ($node->nodeType == DOMIT_ELEMENT_NODE) {			if ($this->documentElement == null) {				parent::appendChild($node);			}			else {				parent::replaceChild($node, $this->documentElement);			}			$this->documentElement =& $node;		}		else {			DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,				('Cannot add a node of type ' . get_class($node) . ' as a Document Element.'));		}		return $node;	} //setDocumentElement	/**	* Appends a node to the childNodes list of the current node	* @param Object The node to be appended	* @return Object The appended node	*/	function &appendChild(&$node) {		if ($node->nodeType == DOMIT_ELEMENT_NODE) {			if ($this->documentElement == null) {				parent::appendChild($node);				$this->setDocumentElement($node);			}			else {				//error thrown if documentElement already exists!				DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,					('Cannot have more than one root node (documentElement) in a DOMIT_Document.'));			}		}		else {			DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,				('Cannot add a node of type ' . get_class($node) . ' to a DOMIT_Document.'));		}		return $node;	} //appendChild	/**	* 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 (($this->documentElement != null) && ($oldChild->uid == $this->documentElement->uid)) {				if ($node->nodeType == DOMIT_ELEMENT_NODE) {					//replace documentElement with new node					$this->setDocumentElement($newChild);				}				else {					DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,						('Cannot replace Document Element with a node of class ' . get_class($newChild)));				}			}			else {				if ($node->nodeType == DOMIT_ELEMENT_NODE) {					if ($this->documentElement != null) {						DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,							('Cannot have more than one root node (documentElement) in a DOMIT_Document.'));					}					else {						parent::replaceChild($newChild, $oldChild);					}				}				else {					DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,						('Nodes of class ' . get_class($newChild) . ' cannot be children of a DOMIT_Document.'));				}			}		return $newChild;	} //replaceChild	/**	* 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) {		$type = $newChild->nodeType;		if ($type == DOMIT_ELEMENT_NODE) {			if ($this->documentElement == null) {				parent::insertBefore($newChild, $refChild);				$this->setDocumentElement($newChild);			}			else {				//error thrown if documentElement already exists!				DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,					('Cannot have more than one root node (documentElement) in a DOMIT_Document.'));			}		}		else {			DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,				('Cannot insert a node of type ' . get_class($newChild) . ' to a DOMIT_Document.'));		}		return $newChild;	} //insertBefore	/**	* 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->documentElement != null) && ($oldChild->uid == $this->documentElement->uid)) {			parent::removeChild($oldChild);			$this->documentElement = null;		}		else {			parent::removeChild($oldChild);		}		$oldChild->clearReferences();		return $oldChild;	} //removeChild	/**	* Creates a new DOMIT_Lite_Element node	* @param string The tag name of the element	* @return Object The new element	*/	function &createElement($tagName) {		$node = new DOMIT_Lite_Element($tagName);		$node->ownerDocument = $this;		$reference =& $node;		return $node;	} //createElement	/**	* Creates a new DOMIT_Text node	* @param string The text of the node	* @return Object The new text node	*/	function &createTextNode($data) {		$node = new DOMIT_Lite_TextNode($data);		$node->ownerDocument = $this;		$reference =& $node;		return $reference;	} //createTextNode	/**	* Creates a new DOMIT_Lite_CDATASection node	* @param string The text of the CDATASection	* @return Object The new CDATASection node	*/	function &createCDATASection($data) {		$node = new DOMIT_Lite_CDATASection($data);		$node->ownerDocument = $this;		return $node;	} //createCDATASection	/**	* Retrieves a NodeList of child elements with the specified tag name	* @param string The matching element tag name

⌨️ 快捷键说明

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