public function fromArray($array)
{
foreach ($array as $key => $value) {
$element = null;
$attribute = null;
$hash_position = strpos($key, '#');
if ($hash_position === false) {
$element = $key;
} elseif ($hash_position === 0) {
$attribute = substr($key, 1);
} else {
list($element, $attribute) = explode('#', $key, 2);
}
if (!is_null($element)) {
if (!is_null($attribute)) {
$this->{$element}[$attribute] = $value;
} else {
if (is_array($value)) {
// Detect numeric arrays and treat them as multiple
// instances of the same key.
$firstKey = key($value);
if ($firstKey === 0) {
if (strpos($element, ':') !== false) {
list($ns) = explode(':', $element, 2);
$baseNode = $this->_element->ownerDocument->createElementNS(Horde_Xml_Element::lookupNamespace($ns), $element);
} else {
$baseNode = $this->_element->ownerDocument->createElement($element);
}
foreach ($value as $v) {
$node = $baseNode->cloneNode();
if (is_array($v)) {
$e = new Horde_Xml_Element($node);
$e->fromArray($v);
} else {
$node->nodeValue = $v;
$e = new Horde_Xml_Element($node);
}
$this->appendChild($e);
}
} else {
$this->{$element}->fromArray($value);
}
} else {
$this->{$element} = $value;
}
}
} elseif (!is_null($attribute)) {
$this[$attribute] = $value;
}
}
}