Index: branches/RC/core/units/general/xml_helper.php =================================================================== diff -u -r10251 -r10294 --- branches/RC/core/units/general/xml_helper.php (.../xml_helper.php) (revision 10251) +++ branches/RC/core/units/general/xml_helper.php (.../xml_helper.php) (revision 10294) @@ -9,15 +9,18 @@ * @var kXMLNode */ var $CurrentElement = null; + + var $Mode; /** * Parses XML data specified and returns root node * * @param string $xml * @return kXMLNode */ - function &Parse($xml = null) + function &Parse($xml = null, $mode=XML_NO_TEXT_NODES) { + $this->Mode = $mode; $this->Clear(); // in case if Parse method is called more then one time $xml_parser = xml_parser_create(); xml_set_element_handler( $xml_parser, Array(&$this, 'startElement'), Array(&$this, 'endElement') ); @@ -34,7 +37,26 @@ return $root_copy; } - + + function ConvertHTMLEntities($s){ + //build first an assoc. array with the entities we want to match + $table1 = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES); + + $patterns = array(); + $replacements = array(); + //now build another assoc. array with the entities we want to replace (numeric entities) + foreach ($table1 as $k=>$v){ + $patterns[] = "/$v/"; + // $c = htmlentities($k,ENT_QUOTES,"UTF-8"); + $replacements[] = "&#".ord($k).";"; + } + + //now perform a replacement using preg_replace + //each matched value in array 1 will be replaced with the corresponding value in array 2 + $s = preg_replace($patterns,$replacements,$s); + return $s; + } + function startElement(&$Parser, &$Elem, $Attrs) { $parent =& $this->CurrentElement; // 1. $parent is now reference to $this->CurrentElement @@ -49,11 +71,21 @@ function characterData($Parser, $Line) { + if ($this->Mode == XML_WITH_TEXT_NODES) { + $text_node = new kXMLNode('_TEXT_'); + $text_node->AppendData($Line); + $this->CurrentElement->AddChild( $text_node ); + } $this->CurrentElement->AppendData($Line); } function endElement($Parser, $Elem) { + if ($this->Mode == XML_WITH_TEXT_NODES) { + /*if (count($this->CurrentElement->Children) == 1 && $this->CurrentElement->firstChild->Name == '_TEXT_') { + $this->CurrentElement->Children = array(); + }*/ + } if ($this->CurrentElement->Parent != null) { $this->CurrentElement =& $this->CurrentElement->Parent; } @@ -86,11 +118,16 @@ * @var int */ var $Position = 0; + + var $CRC = null; function kXMLNode($name, $attrs = array()) { - $this->Name = $name; - $this->Attributes = $attrs; + $this->Name = strtoupper($name); + foreach ($attrs as $attr => $value) { + $this->Attributes[strtoupper($attr)] = $value; + } + $this->CRC = crc32($this->Name.join(array_keys($this->Attributes)).join(array_values($this->Attributes))); } function SetParent(&$elem) @@ -184,6 +221,27 @@ return $child->Data; } } + + /** + * Returns next node to this, false in case of end list + * + * @return kXMLNode + */ + function &PrevSibling() + { + if (!is_null($this->Parent) && $this->Position > 0) { + $pos = $this->Position - 1; + do { + $ret =& $this->Parent->GetChildByPosition($pos--); + } while ($ret->Name == '_TEXT_' && $pos >= 0); + if ($ret->Name == '_TEXT_') $ret = false; + return $ret; + } + else { + $false = false; + return $false; + } + } /** * Returns next node to this, false in case of end list @@ -193,7 +251,11 @@ function &NextSibling() { if (!is_null($this->Parent)) { - $ret =& $this->Parent->GetChildByPosition($this->Position + 1); + $pos = $this->Position + 1; + do { + $ret =& $this->Parent->GetChildByPosition($pos++); + } while ($ret->Name == '_TEXT_' && $pos < count($this->Parent->Children)); + if ($ret->Name == '_TEXT_') $ret = false; return $ret; } else {