diff options
author | Urban Müller | 2010-01-21 14:20:40 +0000 |
---|---|---|
committer | Urban Müller | 2010-01-21 14:20:40 +0000 |
commit | 3b169fe46119eb733e697bdc5506d1d04e2208f8 (patch) | |
tree | 0d70c2358fea2abdc12ff9ef0ea1618b7c76d5b6 | |
parent | aac5517f134f8740b63946120b8fcfc977e4dcd3 (diff) | |
download | itools-3b169fe46119eb733e697bdc5506d1d04e2208f8.tar.gz itools-3b169fe46119eb733e697bdc5506d1d04e2208f8.tar.bz2 itools-3b169fe46119eb733e697bdc5506d1d04e2208f8.zip |
allow setting of subtrees
-rw-r--r-- | it_xml.class | 38 |
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; +} + } ?> |