/** * Convert an Array to XML * @param string $node_name - name of the root node to be converted * @param array $arr - aray to be converterd * @return DomDocument */ public static function &createXML($node_name, $arr = array()) { $xml = self::getXMLRoot(); $xml->appendChild(self::convert($node_name, $arr)); self::$xml = null; // clear the xml node in the class for 2nd time use. return $xml; }
/** * Convert an Array to XML * @param string $node_name - name of the root node to be converted * @param array $arr - aray to be converterd * @return DomDocument */ public static function &createXML($node_name, $arr = array()) { $xml = self::getXMLRoot(); /****** PATCH ***/ //http://www.lalit.org/lab/convert-php-array-to-xml-with-attributes/#comment-23469 // remove // $xml->appendChild(self::convert($node_name, $arr)); // add if (count($arr) > 1) { $xml->appendChild(self::convert($node_name, $arr)); } else { $root_element = @array_pop(array_keys($arr)); $xml->insertBefore(self::convert($root_element, $arr[$root_element])); } // fin add self::$xml = null; // clear the xml node in the class for 2nd time use. return $xml; }