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

📄 xml_domit_parser.php

📁 Joomla!是一套获得过多个奖项的内容管理系统(Content Management System, CMS)。Joomla!采用PHP+MySQL数据库开发
💻 PHP
📖 第 1 页 / 共 5 页
字号:
			for ($i = 0; $i < $total; $i++) {				$currChild =& $oldChild->childNodes[$i];				$this->removeChild($currChild);			}		}		else {			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_DocumentFragment node	* @return Object The new document fragment node	*/	function &createDocumentFragment() {		$node = new DOMIT_DocumentFragment();		$node->ownerDocument =& $this;		return $node;	} //createDocumentFragment	/**	* Creates a new DOMIT_Attr node	* @param string The name of the attribute	* @return Object The new attribute node	*/	function &createAttribute($name) {		$node = new DOMIT_Attr($name);		return $node;	} //createAttribute	/**	* Creates a new DOMIT_Attr node (namespace aware)	* @param string The namespaceURI of the attribute	* @param string The qualifiedName of the attribute	* @return Object The new attribute node	*/	function &createAttributeNS($namespaceURI, $qualifiedName) {		$node = new DOMIT_Attr($qualifiedName);		$node->namespaceURI = $namespaceURI;		$colonIndex = strpos($qualifiedName, ":");		if ($colonIndex !== false) {	    	$node->prefix = substr($qualifiedName, 0, $colonIndex);	    	$node->localName = substr($qualifiedName, ($colonIndex + 1));		}		else {			$node->prefix = '';			$node->localName = $qualifiedName;		}		return $node;	} //createAttributeNS	/**	* Creates a new DOMIT_Element node	* @param string The tag name of the element	* @return Object The new element	*/	function &createElement($tagName) {		$node = new DOMIT_Element($tagName);		$node->ownerDocument =& $this;		return $node;	} //createElement	/**	* Creates a new DOMIT_Element node (namespace aware)	* @param string The namespaceURI of the element	* @param string The qualifiedName of the element	* @return Object The new element	*/	function &createElementNS($namespaceURI, $qualifiedName) {	    $node = new DOMIT_Element($qualifiedName);	    $colonIndex = strpos($qualifiedName, ":");		if ($colonIndex !== false) {	    	$node->prefix = substr($qualifiedName, 0, $colonIndex);	    	$node->localName = substr($qualifiedName, ($colonIndex + 1));		}		else {			$node->prefix = '';	    	$node->localName = $qualifiedName;		}	    $node->namespaceURI = $namespaceURI;		$node->ownerDocument =& $this;		return $node;	} //createElementNS	/**	* 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_TextNode($data);		$node->ownerDocument =& $this;		return $node;	} //createTextNode	/**	* Creates a new DOMIT_CDataSection node	* @param string The text of the CDATASection	* @return Object The new CDATASection node	*/	function &createCDATASection($data) {		$node = new DOMIT_CDATASection($data);		$node->ownerDocument =& $this;		return $node;	} //createCDATASection	/**	* Creates a new DOMIT_Comment node	* @param string The comment text	* @return Object The new comment node	*/	function &createComment($text) {		$node = new DOMIT_Comment($text);		$node->ownerDocument =& $this;		return $node;	} //createComment	/**	* Creates a new DOMIT_ProcessingInstruction node	* @param string The target of the processing instruction	* @param string The data of the processing instruction	* @return Object The new processing instruction node	*/	function &createProcessingInstruction($target, $data) {		$node = new DOMIT_ProcessingInstruction($target, $data);		$node->ownerDocument =& $this;		return $node;	} //createProcessingInstruction	/**	* Retrieves a NodeList of child elements with the specified tag name	* @param string The matching element tag name	* @return Object A NodeList of found elements	*/	function &getElementsByTagName($tagName) {		$nodeList = new DOMIT_NodeList();		if ($this->documentElement != null) {			$this->documentElement->getNamedElements($nodeList, $tagName);		}		return $nodeList;	} //getElementsByTagName	/**	* Retrieves a NodeList of child elements with the specified namespaceURI and localName	* @param string The matching namespaceURI	* @param string The matching localName	* @return Object A NodeList of found elements	*/	function &getElementsByTagNameNS($namespaceURI, $localName) {		$nodeList = new DOMIT_NodeList();		if ($this->documentElement != null) {			$this->documentElement->getNamedElementsNS($nodeList, $namespaceURI, $localName);		}		return $nodeList;	} //getElementsByTagNameNS	/**	* Returns the element whose ID is given by elementId.	* @param string The id of the matching element	* @param boolean True if XML spec is to be strictly adhered to (only attributes xml:id are considered valid)	* @return Object The found element or null	*/	function &getElementByID($elementID, $isStrict = true) {		if ($this->isNamespaceAware) {			if ($this->documentElement != null) {				$targetAttrNode =& $this->documentElement->_getElementByID($elementID, $isStrict);				return $targetAttrNode->ownerElement;			}			$null = null;			return $null;		}		else {			DOMIT_DOMException::raiseException(DOMIT_INVALID_ACCESS_ERR,			 	'Namespace awareness must be enabled to use method getElementByID');		}	} //getElementByID	/**	* Retrieves an element or DOMIT_NodeList of elements corresponding to an Xpath-like expression.	* @param string The query pattern	* @param int If a single node is to be returned (rather than the entire NodeList) the index of that node	* @return mixed A NodeList or single node that matches the pattern	*/	function &getElementsByPath($pattern, $nodeIndex = 0) {		require_once(DOMIT_INCLUDE_PATH . 'xml_domit_getelementsbypath.php');		$gebp = new DOMIT_GetElementsByPath();		$myResponse =& $gebp->parsePattern($this, $pattern, $nodeIndex);		return $myResponse;	} //getElementsByPath	/**	* Retrieves an element or DOMIT_NodeList of elements corresponding to an Xpath-like attribute expression (NOT YET IMPLEMENTED!)	* @param string The query pattern	* @param int If a single node is to be returned (rather than the entire NodeList) the index of that node	* @return mixed A NodeList or single node that matches the pattern	*/	function &getElementsByAttributePath($pattern, $nodeIndex = 0) {		require_once(DOMIT_INCLUDE_PATH . 'xml_domit_getelementsbypath.php');		$gabp = new DOMIT_GetElementsByAttributePath();		$myResponse =& $gabp->parsePattern($this, $pattern, $nodeIndex);		return $myResponse;	} //getElementsByAttributePath	/**	* Retrieves all child nodes of the specified nodeType	* @param string The nodeType of matching nodes	* @param Object The root node of the search	* @return Object A NodeList containing found nodes	*/	function &getNodesByNodeType($type, &$contextNode) {		$nodeList = new DOMIT_NodeList();		if (($type == DOMIT_DOCUMENT_NODE) || ($contextNode->nodeType == DOMIT_DOCUMENT_NODE)){			$nodeList->appendNode($this);		}		else if ($contextNode->nodeType == DOMIT_ELEMENT_NODE) {			$contextNode->getTypedNodes($nodeList, $type);		}		else if ($contextNode->uid == $this->uid) {			if ($this->documentElement != null) {				if ($type == DOMIT_ELEMENT_NODE) {					$nodeList->appendNode($this->documentElement);				}				$this->documentElement->getTypedNodes($nodeList, $type);			}		}		return $nodeList;	} //getNodesByNodeType	/**	* Retrieves all child nodes of the specified nodeValue	* @param string The nodeValue of matching nodes	* @param Object The root node of the search	* @return Object A NodeList containing found nodes	*/	function &getNodesByNodeValue($value, &$contextNode) {		$nodeList = new DOMIT_NodeList();		 if ($contextNode->uid == $this->uid) {			 if ($this->nodeValue == $value) {				 $nodeList->appendNode($this);			 }		 }		if ($this->documentElement != null) {			$this->documentElement->getValuedNodes($nodeList, $value);		}		return $nodeList;	} //getNodesByNodeValue	/**	* Parses an xml string	* @param string The xml text to be parsed	* @param boolean True if SAXY is to be used instead of Expat	* @param boolean False if CDATA Section are to be generated as Text nodes	* @param boolean True if onLoad is to be called on each node after parsing	* @return boolean True if parsing is successful	*/	function parseXML($xmlText, $useSAXY = true, $preserveCDATA = true, $fireLoadEvent = false) {		require_once(DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php');        if ($this->doResolveErrors) {            require_once(DOMIT_INCLUDE_PATH . 'xml_domit_doctor.php');            $xmlText = DOMIT_Doctor::fixAmpersands($xmlText);        }		if (DOMIT_Utilities::validateXML($xmlText)) {			$domParser = new DOMIT_Parser();			if ($useSAXY || (!function_exists('xml_parser_create'))) {				//use SAXY parser to populate xml tree				$this->parser = 'SAXY';				$success = $domParser->parseSAXY($this, $xmlText, $preserveCDATA, $this->definedEntities);			}			else {				//use Expat parser to populate xml tree				$this->parser = 'EXPAT';				$success = $domParser->parse($this, $xmlText, $preserveCDATA);			}			if ($fireLoadEvent && ($this->documentElement != null)) $this->load($this->documentElement);			return $success;		}		else {			return false;		}	} //parseXML	/**	* Parses an xml file	* @param string The xml file to be parsed	* @param boolean True if SAXY is to be used instead of Expat	* @param boolean False if CDATA Section are to be generated as Text nodes	* @param boolean True if onLoad is to be called on each node after parsing	* @return boolean True if parsing is successful	*/	function loadXML($filename, $useSAXY = true, $preserveCDATA = true, $fireLoadEvent = false) {		$xmlText = $this->getTextFromFile($filename);		return $this->parseXML($xmlText, $useSAXY, $preserveCDATA, $fireLoadEvent);	} //loadXML	/**	* Establishes a connection, given an url	* @param string The url of the data	*/	function establishConnection($url) {		require_once(DOMIT_INCLUDE_PATH . 'php_http_client_generic.php');		$host = php_http_connection::formatHost($url);		$host = substr($host, 0, strpos($host, '/'));		$this->setConnection($host);	} //establishConnection	/**	* Retrieves text from a file	* @param string The file path	* @return string The text contained in the file	*/	function getTextFromFile($filename) {		if ($this->doUseHTTPClient && (substr($filename, 0, 5) == 'http:')) {			$this->establishConnection($filename);		}		if ($this->httpConnection != null) {			$response =& $this->httpConnection->get($filename);			$this->httpConnection->disconnect();			return $response->getResponse();		}		else if (function_exists('file_get_contents')) {		    //if (file_exists($filename)) {				return file_get_contents($filename);		    //}		}		else {			require_once(DOMIT_INCLUDE_PATH . 'php_file_utilities.php');			$fileContents =& php_file_utilities::getDataFromFile($filename, 'r');			return $fileContents;		}		return '';	} //getTextFromFile	/**	* Saves the current DOM document as an xml file	* @param string The path of the xml file	* @param boolean True if xml text is to be normalized before saving	* @return boolean True if save is successful	*/	function saveXML($filename, $normalized = false) {		if ($normalized) {			$stringRep = $this->toNormalizedString(false, true);		}		else {			$stringRep = $this->toString(false, true);		}		return $this->saveTextToFile($filename, $stringRep);	} //saveXML	/**	* Saves text to a file	* @param string The file path	* @param string The text to be saved	* @return boolean True if the save is successful	*/	function saveTextToFile($filename, $text) {		if (function_exists('file_put_contents')) {			file_put_contents($filename, $text);		}		else {			require_once(DOMIT_INCLUDE_PATH . 'php_file_utilities.php');			php_file_utilities::putDataToFile($filename, $text, 'w');		}		return (file_exists($filename) && is_writable($filename));	} //saveTextToFile	/**	* Indicates the SAX parser used to parse the current document	* @return string Either "SAXY" or "EXPAT"	*/

⌨️ 快捷键说明

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