summaryrefslogtreecommitdiff
path: root/it_xml.class
diff options
context:
space:
mode:
Diffstat (limited to 'it_xml.class')
-rw-r--r--it_xml.class38
1 files changed, 38 insertions, 0 deletions
diff --git a/it_xml.class b/it_xml.class
index e38d7de..7dd82c7 100644
--- a/it_xml.class
+++ b/it_xml.class
@@ -327,6 +327,44 @@ function error()
return is_a($this, "it_xml") ? $this->error : $GLOBALS['IT_XML_ERROR'];
}
+/**
+ * Set nodes as subnode of current node
+ * @param values assoc array of key => value pairs. May contain associative or numeric subarrays.
+ */
+
+function set($vals)
+{
+ if (is_array($vals))
+ {
+ foreach ($vals as $key => $val)
+ {
+ $classname = $this->_p['prefix'] . $this->_make_identifier($key);
+ if (!class_exists($classname))
+ eval("class $classname extends it_xml {}");
+
+ if (is_array($val) && $val === array_values($val))
+ {
+ $arr = (array)$this->$key;
+ foreach ($val as $i => $v)
+ {
+ if (!is_a($arr[$i], "it_xml"))
+ $arr[$i] = new $classname;
+ $arr[$i]->set($v);
+ }
+ $this->$key = $arr;
+ }
+ else
+ {
+ if (!is_a($this->$key, "it_xml"))
+ $this->$key = new $classname;
+ $this->$key->set($val);
+ }
+ }
+ }
+ else
+ $this->val = $vals;
+}
+
}
?>