• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/classes/mysql/cml2.php
  • Класс: CIBlockXMLFile
  • Вызов: CIBlockXMLFile::_start_element
function _start_element($xmlChunk)
{
	static $search = array(
			"'&(quot|#34);'i",
			"'&(lt|#60);'i",
			"'&(gt|#62);'i",
			"'&(amp|#38);'i",
		);

	static $replace = array(
			""",
			"<",
			">",
			"&",
		);

	$p = strpos($xmlChunk, ">");
	if($p !== false)
	{
		if(substr($xmlChunk, $p - 1, 1) == "/")
		{
			$bHaveChildren = false;
			$elementName = substr($xmlChunk, 0, $p - 1);
			$DBelementValue = false;
		}
		else
		{
			$bHaveChildren = true;
			$elementName = substr($xmlChunk, 0, $p);
			$elementValue = substr($xmlChunk, $p + 1);
			if(preg_match("/^s*$/", $elementValue))
				$DBelementValue = false;
			elseif(strpos($elementValue, "&") === false)
				$DBelementValue = $elementValue;
			else
				$DBelementValue = preg_replace($search, $replace, $elementValue);
		}

		if(($ps = strpos($elementName, " "))!==false)
		{
			//Let's handle attributes
			$elementAttrs = substr($elementName, $ps + 1);
			$elementName = substr($elementName, 0, $ps);
			preg_match_all("/(\S+)\s*=\s*["](.*?)["]/s".BX_UTF_PCRE_MODIFIER, $elementAttrs, $attrs_tmp);
			$attrs = array();
			if(strpos($elementAttrs, "&") === false)
			{
				foreach($attrs_tmp[1] as $i=>$attrs_tmp_1)
					$attrs[$attrs_tmp_1] = $attrs_tmp[2][$i];
			}
			else
			{
				foreach($attrs_tmp[1] as $i=>$attrs_tmp_1)
					$attrs[$attrs_tmp_1] = preg_replace($search, $replace, $attrs_tmp[2][$i]);
			}
			$DBelementAttrs = serialize($attrs);
		}
		else
			$DBelementAttrs = false;

		if($c = count($this->element_stack))
			$parent = $this->element_stack[$c-1];
		else
			$parent = array("ID"=>"NULL", "L"=>0, "R"=>1);

		$left = $parent["R"];
		$right = $left+1;

		$arFields = array(
			"PARENT_ID" => $parent["ID"],
			"LEFT_MARGIN" => $left,
			"RIGHT_MARGIN" => $right,
			"DEPTH_LEVEL" => $c,
			"NAME" => $elementName,
		);
		if($DBelementValue !== false)
		{
			$arFields["VALUE"] = $DBelementValue;
		}
		if($DBelementAttrs !== false)
		{
			$arFields["ATTRIBUTES"] = $DBelementAttrs;
		}

		$ID = $this->Add($arFields);

		if($bHaveChildren)
			$this->element_stack[] = array("ID"=>$ID, "L"=>$left, "R"=>$right, "RO"=>$right);
		else
			$this->element_stack[$c-1]["R"] = $right+1;
	}
}