Index: branches/5.2.x/core/units/helpers/xml_helper.php =================================================================== diff -u -N -r14588 -r14607 --- branches/5.2.x/core/units/helpers/xml_helper.php (.../xml_helper.php) (revision 14588) +++ branches/5.2.x/core/units/helpers/xml_helper.php (.../xml_helper.php) (revision 14607) @@ -1,6 +1,6 @@ Mode = !isset($mode) ? self::XML_NO_TEXT_NODES : $mode; $this->Clear(); // in case if Parse method is called more then one time $xml_parser = xml_parser_create(); - if ($no_case_folding) { + if ( $no_case_folding ) { xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0); } - xml_set_element_handler( $xml_parser, Array(&$this, 'startElement'), Array(&$this, 'endElement') ); - xml_set_character_data_handler( $xml_parser, Array(&$this, 'characterData') ); + xml_set_element_handler($xml_parser, Array (&$this, 'startElement'), Array (&$this, 'endElement')); + xml_set_character_data_handler($xml_parser, Array (&$this, 'characterData')); if ( !xml_parse($xml_parser, $xml, 1) ) { $class_name = $this->XMLNodeClassName; $byte = xml_get_current_byte_index($xml_parser); - $extract = '...' . mb_substr($xml, $byte-50, 50) . ' !!![' . mb_substr($xml, $byte, 1) . ']!!! '.mb_substr($xml, $byte+1, 50) . '...'; + $extract = '...' . mb_substr($xml, $byte - 50, 50) . ' !!![' . mb_substr($xml, $byte, 1) . ']!!! ' . mb_substr($xml, $byte + 1, 50) . '...'; $message = sprintf( 'XML error number %s: %s at line %d col %d, byte %d, extract: %s', xml_get_error_code($xml_parser), - xml_error_string(xml_get_error_code($xml_parser)), + xml_error_string( xml_get_error_code($xml_parser) ), xml_get_current_line_number($xml_parser), xml_get_current_column_number($xml_parser), xml_get_current_byte_index($xml_parser), $extract ); - $this->RootElement =& new $class_name( - 'ERROR', - array( - 'code' => xml_get_error_code($xml_parser), - 'message' => $message - ) - ); + $this->RootElement =& new $class_name('ERROR', array ('code' => xml_get_error_code($xml_parser), 'message' => $message)); - trigger_error($message, E_USER_WARNING); + trigger_error($message, E_USER_WARNING); } xml_parser_free($xml_parser); $root_copy = $this->RootElement; + /* @var $root_copy kXMLNode */ + unset($this->RootElement); unset($this->CurrentElement); @@ -149,6 +153,8 @@ if ($this->Mode == self::XML_WITH_TEXT_NODES) { $class_name = $this->XMLNodeClassName; $text_node = new $class_name('_TEXT_'); + /* @var $text_node kXMLNode */ + $text_node->AppendData($Line); $this->CurrentElement->AddChild( $text_node ); } @@ -187,6 +193,23 @@ } return $node; } + + /** + * Checks, that there is no error during XML document parsing + * + * @param kXMLNode $root_node + * @param string $root_node_name + * @return bool + * @access public + */ + public function isError(&$root_node, $root_node_name) + { + if ( !is_object($root_node) || !preg_match('/^kxmlnode/i', get_class($root_node)) || ($root_node->Name == 'ERROR') || ($root_node->Name != $root_node_name) ) { + return true; + } + + return false; + } } class kXMLNode { @@ -220,11 +243,12 @@ var $OriginalAttributes = array(); /** - * List of node childnodes + * List of node child nodes * * @var Array + * @access public */ - var $Children = array(); + public $Children = Array (); /** * Node content (usually text) @@ -268,17 +292,17 @@ */ var $CRC = null; - function kXMLNode($name, $attrs = array()) + function __construct($name, $attributes = Array()) { $this->Name = strtoupper($name); $this->OriginalName = $name; - $this->OriginalAttributes = $attrs; + $this->OriginalAttributes = $attributes; - foreach ($attrs as $attr => $value) { - $this->Attributes[ strtoupper($attr) ] = $value; + foreach ($attributes as $attr => $value) { + $this->Attributes[strtoupper($attr)] = $value; } - $this->CRC = crc32($this->Name.join(array_keys($this->Attributes)).join(array_values($this->Attributes))); + $this->CRC = crc32($this->Name . implode('', array_keys($this->Attributes)) . implode('', array_values($this->Attributes))); } /** @@ -367,9 +391,8 @@ function GetChildValue($path) { $child =& $this->GetChild($path); - if ($child !== false) { - return $child->Data; - } + + return $child !== false ? $child->Data : ''; } /** @@ -398,43 +421,54 @@ function &FindChild($name) { $name = strtoupper($name); - if ($this->Name == $name) return $this; - // if (isset($this->Children[$name])) return $this->Children[$name]; - // $children = array_keys($this->Children); - foreach ($this->Children as $elem) - { + if ( $this->Name == $name ) { + return $this; + } + + /*if ( isset($this->Children[$name]) ) { + return $this->Children[$name]; + } + + $children = array_keys($this->Children);*/ + + foreach ($this->Children as $elem) { + /* @var $elem kXMLNode */ + $child =& $elem->FindChild($name); - if ($child !== false) - { + if ( $child !== false ) { return $child; } } - if (isset($child) && is_object($child)) { + if ( isset($child) && is_object($child) ) { $child->_destruct(); } + unset($child); $false = false; return $false; } /** - * Retruns value of given child or value of it's attribute + * Returns value of given child or value of it's attribute * * @param string $name * @param string $attr * @return string + * @access public */ - function FindChildValue($name, $attr=null) + public function FindChildValue($name, $attr = null) { $child =& $this->FindChild($name); - if ($child !== false) { - if (isset($attr)) { - return $child->Attributes[strtoupper($attr)]; + if ( $child !== false ) { + if ( isset($attr) ) { + return $child->Attributes[ strtoupper($attr) ]; } return $child->Data; } + + return ''; } /**