Have importing of vars and xml working on any node

This commit is contained in:
seek3r 2002-09-21 00:24:11 +00:00
parent 53704f7ef1
commit 20974436bd

View File

@ -7,17 +7,15 @@
class xmltool class xmltool
{ {
/* shared */ /* for root nodes */
var $node_type = '';
var $comments = Array();
/* for docs */
var $xmlversion = '1.0'; var $xmlversion = '1.0';
var $doctype = Array(); var $doctype = Array();
var $root_node; /* shared */
/* for nodes */ var $node_type = '';
var $name = ''; var $name = '';
var $data;
var $data_type; var $data_type;
var $data;
/* for nodes */
var $attributes = Array(); var $attributes = Array();
var $comments = Array(); var $comments = Array();
var $indentstring = " "; var $indentstring = " ";
@ -40,38 +38,10 @@
} }
} }
function add_root ($node_object)
{
if ($this->node_type == 'root')
{
if(is_object($node_object))
{
$this->root_node = $node_object;
}
else
{
echo 'Not a valid xmltool node object<br>';
exit;
}
}
else
{
echo 'add_root can only be used by a root object<br>';
exit;
}
}
function set_version ($version = '1.0') function set_version ($version = '1.0')
{ {
if ($this->node_type == 'node') $this->xmlversion = $version;
{ return True;
$this->xmlversion = $version;
}
else
{
echo 'set_version can only be used by a root object<br>';
exit;
}
} }
function set_doctype ($name, $uri = '') function set_doctype ($name, $uri = '')
@ -79,55 +49,73 @@
if ($this->node_type == 'root') if ($this->node_type == 'root')
{ {
$this->doctype[$name] = $uri; $this->doctype[$name] = $uri;
return True;
} }
else else
{ {
echo 'set_doctype can only be used by a root object<br>'; return False;
exit;
} }
} }
function add_node ($node_object , $name = '') function add_node ($node_object, $name = '')
{ {
if ($this->node_type == 'node') switch ($this->node_type)
{ {
if (is_object($node_object)) case 'root':
{ if (is_object($node_object))
if(!is_array($this->data))
{ {
$this->data = Array(); $this->data = $node_object;
$this->data_type = 'node';
}
if ($name != '')
{
$this->data[$name] = $node_object;
} }
else else
{ {
$this->data[] = $node_object; $this->data = $this->import_var($name, $node_object);
} }
} break;
else case 'node':
{
if(!is_array($this->data)) if(!is_array($this->data))
{ {
$this->data = Array(); $this->data = Array();
$this->data_type = 'node'; $this->data_type = 'node';
} }
$this->data[$name] = $this->import_var($name, $node_object); if (is_object($node_object))
} {
if ($name != '')
{
$this->data[$name] = $node_object;
}
else
{
$this->data[] = $node_object;
}
}
else
{
$this->data[$name] = $this->import_var($name, $node_object);
}
return True;
break;
} }
else }
function get_node ($name = '')
{
switch ($this->data_type)
{ {
echo 'root objects should use add_root to create the root node<br>'; case 'root':
exit; break;
case 'node':
break;
case 'object':
break;
} }
} }
function set_value ($string) function set_value ($string)
{ {
$this->data = $string; $this->data = $string;
$this->data_type = 'value'; $this->data_type = 'value';
return True;
} }
function get_value () function get_value ()
@ -139,22 +127,13 @@
else else
{ {
return False; return False;
//echo 'get_value can only be used on data type of value.<br>';
exit;
} }
} }
function set_attribute ($name, $value = '') function set_attribute ($name, $value = '')
{ {
if ($this->node_type == 'node') $this->attributes[$name] = $value;
{ return True;
$this->attributes[$name] = $value;
}
else
{
echo 'set_attribute can only be used by a node object<br>';
exit;
}
} }
function get_attribute ($name) function get_attribute ($name)
@ -170,6 +149,7 @@
function add_comment ($comment) function add_comment ($comment)
{ {
$this->comments[] = $comment; $this->comments[] = $comment;
return True;
} }
function import_var($name, $value,$is_root=False,$export_xml=False) function import_var($name, $value,$is_root=False,$export_xml=False)
@ -284,7 +264,7 @@
if($is_root) if($is_root)
{ {
$this->add_root($node); $this->add_node($node);
if($export_xml) if($export_xml)
{ {
$xml = $this->export_xml(); $xml = $this->export_xml();
@ -297,18 +277,25 @@
} }
else else
{ {
$this->add_node($node);
return $node; return $node;
} }
} }
function export_var ($is_start = True) function export_var ($is_start = True)
{ {
if($is_start) switch ($this->data_type)
{ {
//$xmldata = xml_get_tree($xmldata); case 'root':
break;
case 'node':
break;
case 'object':
break;
} }
if($this->datatype != 'node')
if($this->data_type != 'node')
{ {
$data = $this->data; $data = $this->data;
$found_at = strstr($xmldata['value'],'PHP_SERIALIZED_OBJECT:'); $found_at = strstr($xmldata['value'],'PHP_SERIALIZED_OBJECT:');
@ -317,14 +304,14 @@
$data = str_replace ('PHP_SERIALIZED_OBJECT:', '', $this->data); $data = str_replace ('PHP_SERIALIZED_OBJECT:', '', $this->data);
$data = unserialize ($xmldata['value']); $data = unserialize ($xmldata['value']);
} }
if($is_start) //if($is_start)
{ //{
$xml_array[$this->data] = $data; // $xml_array[$this->data] = $data;
} //}
else //else
{ //{
return $data; return $data;
} //}
} }
else else
{ {
@ -430,14 +417,7 @@
case 'closed': case 'closed':
exit; exit;
} }
if($this->node_type == 'root') $this->add_node($node);
{
$this->add_root($node);
}
else
{
$this->add_node($node);
}
} }
function export_xml($indent = 1) function export_xml($indent = 1)
@ -458,10 +438,10 @@
$result .= "<!-- $val -->\n"; $result .= "<!-- $val -->\n";
} }
} }
if(is_object($this->root_node)) if(is_object($this->data))
{ {
$indent = 0; $indent = 0;
$result .= $this->root_node->export_xml($indent); $result .= $this->data->export_xml($indent);
} }
return $result; return $result;
} }