From: Chuck Hagenbuch Date: Thu, 20 Nov 2008 21:03:39 +0000 (-0500) Subject: Support repeated elements in fromArray() X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=e644b54cf83274e06835f3f816b82d1119908c02;p=horde.git Support repeated elements in fromArray() --- diff --git a/framework/Xml_Element/lib/Horde/Xml/Element.php b/framework/Xml_Element/lib/Horde/Xml/Element.php index 8f89c827d..03c45330f 100644 --- a/framework/Xml_Element/lib/Horde/Xml/Element.php +++ b/framework/Xml_Element/lib/Horde/Xml/Element.php @@ -172,7 +172,31 @@ class Horde_Xml_Element implements ArrayAccess $this->{$element}[$attribute] = $value; } else { if (is_array($value)) { - $this->$element->fromArray($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, $elt) = explode(':', $var, 2); + $baseNode = $this->_element->ownerDocument->createElementNS(Horde_Xml_Element::lookupNamespace($ns), $elt); + } 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; }