- if (!is_array($value) AND !is_numeric($key))
- $xml->addChild($key, xmlify($value));
- elseif (is_array($value))
- self::from_array($value, $xml->addChild($key));
+ if ($key == "@attributes") {
+ if (!isset($element) OR !is_array($value))
+ continue;
+
+ foreach ($value as $attr_key => $attr_value) {
+ $element_parts = explode(":", $attr_key);
+ if ((count($element_parts) > 1) AND isset($namespaces[$element_parts[0]]))
+ $namespace = $namespaces[$element_parts[0]];
+ else
+ $namespace = NULL;
+
+ $element->addAttribute ($attr_key, $attr_value, $namespace);
+ }
+
+ continue;
+ }
+
+ $element_parts = explode(":", $key);
+ if ((count($element_parts) > 1) AND isset($namespaces[$element_parts[0]]))
+ $namespace = $namespaces[$element_parts[0]];
+ else
+ $namespace = NULL;
+
+ if (!is_array($value))
+ $element = $xml->addChild($key, xmlify($value), $namespace);
+ elseif (is_array($value)) {
+ $element = $xml->addChild($key, NULL, $namespace);
+ self::from_array($value, $element, $remove_header, $namespaces, false);
+ }