• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/classes/mysql/cml2.php
  • Класс: is
  • Вызов: is::ReadXMLToDatabase
function ReadXMLToDatabase($fp, &$NS, $time_limit=0, $read_size = 1024)
{
	//Initialize object
	if(!array_key_exists("charset", $NS))
		$NS["charset"] = false;
	$this->charset = &$NS["charset"];

	if(!array_key_exists("element_stack", $NS))
		$NS["element_stack"] = array();
	$this->element_stack = &$NS["element_stack"];

	if(!array_key_exists("file_position", $NS))
		$NS["file_position"] = 0;
	$this->file_position = &$NS["file_position"];

	$this->read_size = $read_size;
	$this->buf = "";
	$this->buf_position = 0;
	$this->buf_len = 0;

	//This is an optimization. We assume than no step can take more than one year.
	if($time_limit > 0)
		$end_time = time() + $time_limit;
	else
		$end_time = time() + 365*24*3600; // One year

	$cs = $this->charset;
	fseek($fp, $this->file_position);
	while(($xmlChunk = $this->_get_xml_chunk($fp)) !== false)
	{
		if($cs)
		{
			$xmlChunk = MainTextEncoding::convertEncoding($xmlChunk, $cs, LANG_CHARSET);
		}

		if($xmlChunk[0] == "/")
		{
			$this->_end_element($xmlChunk);
			if(time() > $end_time)
				break;
		}
		elseif($xmlChunk[0] == "!" || $xmlChunk[0] == "?")
		{
			if(strncmp($xmlChunk, "?xml", 4) === 0)
			{
				if(preg_match('#encoding[s]*=[s]*"(.*?)"#i', $xmlChunk, $arMatch))
				{
					$this->charset = $arMatch[1];
					if(strtoupper($this->charset) === strtoupper(LANG_CHARSET))
						$this->charset = false;
					$cs = $this->charset;
				}
			}
		}
		else
		{
			$this->_start_element($xmlChunk);
		}

	}

	return feof($fp);
}