Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Tue, Jun 24, 11:29 PM

in-portal

Index: branches/unlabeled/unlabeled-1.1.2/kernel/units/general/xml_helper.php
===================================================================
--- branches/unlabeled/unlabeled-1.1.2/kernel/units/general/xml_helper.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.1.2/kernel/units/general/xml_helper.php (revision 3924)
@@ -0,0 +1,136 @@
+<?php
+
+class kXMLHelper extends kHelper {
+ var $RootElement = null;
+
+ /**
+ * Enter description here...
+ *
+ * @var kXMLNode
+ */
+ var $CurrentElement = null;
+
+ function &Parse($xml = null)
+ {
+ $xml_parser = xml_parser_create();
+ 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)) {
+ trigger_error(sprintf('XML error: %s at line %d'),
+ xml_error_string(xml_get_error_code($xml_parser)),
+ xml_get_current_line_number($xml_parser), E_USER_WARNING);
+ }
+ xml_parser_free($xml_parser);
+ return $this->RootElement;
+ }
+
+ function startElement(&$Parser, &$Elem, $Attrs)
+ {
+ $parent =& $this->CurrentElement;
+ $this->CurrentElement =& new kXMLNode($Elem, $Attrs);
+ if (is_null($this->RootElement)) {
+ $this->RootElement =& $this->CurrentElement;
+ }
+ if (!is_null($parent)) {
+ $parent->AddChild($this->CurrentElement);
+ }
+ }
+
+ function characterData($Parser, $Line)
+ {
+ $this->CurrentElement->AppendData($Line);
+ }
+
+ function endElement($Parser, $Elem)
+ {
+ if ($this->CurrentElement->Parent != null) {
+ $this->CurrentElement =& $this->CurrentElement->Parent;
+ }
+ }
+
+ function Clear()
+ {
+ $this->RootElement = null;
+ $this->CurrentElement = null;
+ }
+}
+
+class kXMLNode {
+ var $Name = null;
+ var $Attributes = array();
+ var $Children = array();
+ var $Data = null;
+ var $Parent = null;
+
+ function kXMLNode($name, $attrs = array())
+ {
+ $this->Name = $name;
+ $this->Attributes = $attrs;
+ }
+
+ function SetParent(&$elem)
+ {
+ $this->Parent =& $elem;
+ }
+
+ function AddChild(&$a_child)
+ {
+ $this->Children[$a_child->Name] =& $a_child;
+ $a_child->SetParent($this);
+ }
+
+ function AppendData($data)
+ {
+ $this->Data .= $data;
+ }
+
+ function &GetChild($path)
+ {
+ $entries = explode('/', strtoupper($path));
+ $cur = array_shift($entries);
+ if ($cur == $this->Name) $cur = array_shift($entries);
+ if (!$cur) return $this;
+ if (!isset($this->Children[$cur])) return false;
+ $left = implode('/', $entries);
+ if (!$left) return $this->Children[$cur];
+ return $this->Children[$cur]->GetChild($left);
+ }
+
+ function GetChildValue($path)
+ {
+ $child =& $this->GetChild($path);
+ if ($child !== false) {
+ return $child->Data;
+ }
+ }
+
+ function &FindChild($name)
+ {
+ $name = strtoupper($name);
+ if ($this->Name == $name) return $this;
+ if (isset($this->Children[$name])) return $this->Children[$name];
+ $children_names = array_keys($this->Children);
+ foreach ($children_names as $a_name)
+ {
+ $child =& $this->Children[$a_name]->FindChild($name);
+ if ($child !== false)
+ {
+ return $child;
+ }
+ }
+ return false;
+ }
+
+ function FindChildValue($name, $attr=null)
+ {
+ $child =& $this->FindChild($name);
+ if ($child !== false) {
+ if (isset($attr)) {
+ return $child->Attributes[strtoupper($attr)];
+ }
+ return $child->Data;
+ }
+ }
+}
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.1.2/kernel/units/general/xml_helper.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.1.2/core/units/general/xml_helper.php
===================================================================
--- branches/unlabeled/unlabeled-1.1.2/core/units/general/xml_helper.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.1.2/core/units/general/xml_helper.php (revision 3924)
@@ -0,0 +1,136 @@
+<?php
+
+class kXMLHelper extends kHelper {
+ var $RootElement = null;
+
+ /**
+ * Enter description here...
+ *
+ * @var kXMLNode
+ */
+ var $CurrentElement = null;
+
+ function &Parse($xml = null)
+ {
+ $xml_parser = xml_parser_create();
+ 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)) {
+ trigger_error(sprintf('XML error: %s at line %d'),
+ xml_error_string(xml_get_error_code($xml_parser)),
+ xml_get_current_line_number($xml_parser), E_USER_WARNING);
+ }
+ xml_parser_free($xml_parser);
+ return $this->RootElement;
+ }
+
+ function startElement(&$Parser, &$Elem, $Attrs)
+ {
+ $parent =& $this->CurrentElement;
+ $this->CurrentElement =& new kXMLNode($Elem, $Attrs);
+ if (is_null($this->RootElement)) {
+ $this->RootElement =& $this->CurrentElement;
+ }
+ if (!is_null($parent)) {
+ $parent->AddChild($this->CurrentElement);
+ }
+ }
+
+ function characterData($Parser, $Line)
+ {
+ $this->CurrentElement->AppendData($Line);
+ }
+
+ function endElement($Parser, $Elem)
+ {
+ if ($this->CurrentElement->Parent != null) {
+ $this->CurrentElement =& $this->CurrentElement->Parent;
+ }
+ }
+
+ function Clear()
+ {
+ $this->RootElement = null;
+ $this->CurrentElement = null;
+ }
+}
+
+class kXMLNode {
+ var $Name = null;
+ var $Attributes = array();
+ var $Children = array();
+ var $Data = null;
+ var $Parent = null;
+
+ function kXMLNode($name, $attrs = array())
+ {
+ $this->Name = $name;
+ $this->Attributes = $attrs;
+ }
+
+ function SetParent(&$elem)
+ {
+ $this->Parent =& $elem;
+ }
+
+ function AddChild(&$a_child)
+ {
+ $this->Children[$a_child->Name] =& $a_child;
+ $a_child->SetParent($this);
+ }
+
+ function AppendData($data)
+ {
+ $this->Data .= $data;
+ }
+
+ function &GetChild($path)
+ {
+ $entries = explode('/', strtoupper($path));
+ $cur = array_shift($entries);
+ if ($cur == $this->Name) $cur = array_shift($entries);
+ if (!$cur) return $this;
+ if (!isset($this->Children[$cur])) return false;
+ $left = implode('/', $entries);
+ if (!$left) return $this->Children[$cur];
+ return $this->Children[$cur]->GetChild($left);
+ }
+
+ function GetChildValue($path)
+ {
+ $child =& $this->GetChild($path);
+ if ($child !== false) {
+ return $child->Data;
+ }
+ }
+
+ function &FindChild($name)
+ {
+ $name = strtoupper($name);
+ if ($this->Name == $name) return $this;
+ if (isset($this->Children[$name])) return $this->Children[$name];
+ $children_names = array_keys($this->Children);
+ foreach ($children_names as $a_name)
+ {
+ $child =& $this->Children[$a_name]->FindChild($name);
+ if ($child !== false)
+ {
+ return $child;
+ }
+ }
+ return false;
+ }
+
+ function FindChildValue($name, $attr=null)
+ {
+ $child =& $this->FindChild($name);
+ if ($child !== false) {
+ if (isset($attr)) {
+ return $child->Attributes[strtoupper($attr)];
+ }
+ return $child->Data;
+ }
+ }
+}
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.1.2/core/units/general/xml_helper.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property

Event Timeline