Index: trunk/kernel/units/general/xml_helper.php =================================================================== diff -u -r4358 -r4418 --- trunk/kernel/units/general/xml_helper.php (.../xml_helper.php) (revision 4358) +++ trunk/kernel/units/general/xml_helper.php (.../xml_helper.php) (revision 4418) @@ -10,6 +10,12 @@ */ var $CurrentElement = null; + /** + * Parses XML data specified and returns root node + * + * @param string $xml + * @return kXMLNode + */ function &Parse($xml = null) { $xml_parser = xml_parser_create(); @@ -60,8 +66,22 @@ var $Attributes = array(); var $Children = array(); var $Data = null; + + var $firstChild = null; + var $lastChild = null; + /** + * Parent node + * + * @var kXMLNode + */ var $Parent = null; - + /** + * Node position relative to other nodes of it's parent + * + * @var int + */ + var $Position = 0; + function kXMLNode($name, $attrs = array()) { $this->Name = $name; @@ -73,8 +93,24 @@ $this->Parent =& $elem; } + /** + * Adds new child to current node + * + * @param kXMLNode $a_child + */ function AddChild(&$a_child) { + $node_count = count($this->Children); + $a_child->Position = $node_count; + + if ($node_count == 0) { + $this->firstChild =& $a_child; + $this->lastChild =& $a_child; + } + else { + $this->lastChild =& $a_child; + } + $this->Children[] =& $a_child; $a_child->SetParent($this); } @@ -104,6 +140,17 @@ } } + function &GetChildByPosition($position) + { + if ($position < count($this->Children) ) { + return $this->Children[$position]; + } + else { + $false = false; + return $false; + } + } + function &FindChild($name) { $name = strtoupper($name); @@ -131,6 +178,22 @@ return $child->Data; } } + + /** + * Returns next node to this, false in case of end list + * + * @return kXMLNode + */ + function &NextSibling() + { + if (!is_null($this->Parent)) { + return $this->Parent->GetChildByPosition($this->Position + 1); + } + else { + $false = false; + return $false; + } + } } ?> \ No newline at end of file