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

📄 xml_domit_parser.php

📁 Joomla!是一套获得过多个奖项的内容管理系统(Content Management System, CMS)。Joomla!采用PHP+MySQL数据库开发
💻 PHP
📖 第 1 页 / 共 5 页
字号:
		$this->doctype = null;		$this->documentElement = null;		$this->nodeType = DOMIT_DOCUMENT_NODE;		$this->nodeName = '#document';		$this->ownerDocument =& $this;		$this->parser = '';		$this->implementation = new DOMIT_DOMImplementation();	} //DOMIT_Document	/**	* Specifies whether DOMIT! 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 whether DOMIT! processes namespace information	* @param boolean True if namespaces are to be processed	*/	function setNamespaceAwareness($truthVal) {	    $this->isNamespaceAware = $truthVal;	} //setNamespaceAwareness	/**	* Specifies whether DOMIT! preserves whitespace when parsing	* @param boolean True if whitespace is to be preserved	*/	function preserveWhitespace($truthVal) {	    $this->preserveWhitespace = $truthVal;	} //preserveWhitespace	/**	* 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 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	/**	* Imports a node (and optionally its children) from another DOM Document	* @param object A reference to the node to be imported	* @param boolean True if the children of the imported node are also to be imported	* @return object The imported node (and, if specified, its children)	*/	function &importNode(&$importedNode, $deep = true) {		$parentNode = null;		return $this->_importNode($parentNode, $importedNode, $deep);	} //importNode	/**	* Imports a node (and optionally its children) from another DOM Document	* @param object A reference to the parent of the node to be imported	* @param object A reference to the node to be imported	* @param boolean True if the children of the imported node are also to be imported	* @return object The imported node if it is the top level node, otherwise null	*/	function &_importNode(&$parentNode, &$sourceNode, $deep) {		$hasChildren = false;		switch ($sourceNode->nodeType) {			case DOMIT_ELEMENT_NODE:				$hasChildren = true;				if ($this->isNamespaceAware) {					$importedNode =& $this->createElementNS($sourceNode->namespaceURI,								($sourceNode->prefix . ":" . $sourceNode->localName));				}				else {					$importedNode =& $this->createElement($sourceNode->nodeName);				}				$attrNodes =& $sourceNode->attributes;				$total = $attrNodes->getLength();				for ($i = 0; $i < $total; $i++) {					$attrNode =& $attrNodes->item($i);					if ($this->isNamespaceAware) {						$importedNode->setAttributeNS($attrNode->namespaceURI,							($attrNode->prefix . ":" . $attrNode->localName), $attrNode->nodeValue);					}					else {						$importedNode->setAttribute($attrNode->nodeName, $attrNode->nodeValue);					}				}				break;			case DOMIT_ATTRIBUTE_NODE:				if ($this->isNamespaceAware) {					$importedNode =& $this->createAttributeNS($sourceNode->namespaceURI,								($sourceNode->prefix . ":" . $sourceNode->localName));				}				else {					$importedNode =& $this->createAttribute($sourceNode->nodeValue);				}				break;			case DOMIT_TEXT_NODE:				$importedNode =& $this->createTextNode($sourceNode->nodeValue);				break;			case DOMIT_CDATA_SECTION_NODE:				$importedNode =& $this->createCDATASection($sourceNode->nodeValue);				break;			case DOMIT_COMMENT_NODE:				$importedNode =& $this->createComment($sourceNode->nodeValue);				break;			case DOMIT_DOCUMENT_FRAGMENT_NODE:				$hasChildren = true;				$importedNode =& $this->createDocumentFragment();				break;			case DOMIT_PROCESSING_INSTRUCTION_NODE:				$importedNode =& $this->createProcessingInstruction($sourceNode->nodeName,																	$sourceNode->nodeValue);				break;			case DOMIT_DOCUMENT_NODE:			case DOMIT_DOCUMENT_TYPE_NODE:				DOMIT_DOMException::raiseException(DOMIT_NOT_SUPPORTED_ERR,					('Method importNode cannot be called by class ' . get_class($this)));				break;		}		if ($hasChildren && $deep) {			$total = $sourceNode->childCount;			for ($i = 0; $i < $total; $i++) {				$importedNode->appendChild(						$this->_importNode($importedNode, $sourceNode->childNodes[$i], $deep));			}		}		return $importedNode;	} //_importNode	/**	* 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) {	    switch ($node->nodeType) {	        case 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.'));				}	            break;			case DOMIT_PROCESSING_INSTRUCTION_NODE:			case DOMIT_COMMENT_NODE:			    parent::appendChild($node);			    break;   			case DOMIT_DOCUMENT_TYPE_NODE:   			    if ($this->doctype == null) {					parent::appendChild($node);				}				else {					DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,						('Cannot have more than one doctype node in a DOMIT_Document.'));				}   			    break;			case DOMIT_DOCUMENT_FRAGMENT_NODE:			    $total = $node->childCount;				for ($i = 0; $i < $total; $i++) {					$currChild =& $node->childNodes[$i];					$this->appendChild($currChild);				}			    break;   			default:   			    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->nodeType == DOMIT_DOCUMENT_FRAGMENT_NODE) {			$total = $newChild->childCount;			if ($total > 0) {				$newRef =& $newChild->lastChild;				$this->replaceChild($newRef, $oldChild);				for ($i = 0; $i < ($total - 1); $i++) {					$currChild =& $newChild->childNodes[$i];					parent::insertBefore($currChild, $newRef);				}			}		}		else {			if (($this->documentElement != null) && ($oldChild->uid == $this->documentElement->uid)) {				if ($newChild->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 {				switch ($newChild->nodeType) {				    case 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);						}				        break;					case DOMIT_PROCESSING_INSTRUCTION_NODE:					case DOMIT_COMMENT_NODE:					    parent::replaceChild($newChild, $oldChild);					    break;	 				case DOMIT_DOCUMENT_TYPE_NODE:	 				    if ($this->doctype != null) {							if ($this->doctype->uid == $oldChild->uid) {								parent::replaceChild($newChild, $oldChild);							}							else {								DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,									('Cannot have more than one doctype node in a DOMIT_Document.'));							}						}						else {							parent::replaceChild($newChild, $oldChild);						}	 				    break;	  				default:	  				    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 ($this->nodeType == DOMIT_DOCUMENT_FRAGMENT_NODE) {			$total = $newChild->childCount;			for ($i = 0; $i < $total; $i++) {				$currChild =& $newChild->childNodes[$i];				$this->insertBefore($currChild, $refChild);			}		}		else 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 if ($type == DOMIT_PROCESSING_INSTRUCTION_NODE) {			parent::insertBefore($newChild, $refChild);		}		else if ($type == DOMIT_DOCUMENT_TYPE_NODE) {			if ($this->doctype == null) {				parent::insertBefore($newChild, $refChild);			}			else {				DOMIT_DOMException::raiseException(DOMIT_HIERARCHY_REQUEST_ERR,					('Cannot have more than one doctype node 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->nodeType == DOMIT_DOCUMENT_FRAGMENT_NODE) {			$total = $oldChild->childCount;

⌨️ 快捷键说明

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