/** * Convert an associative array to XML * If array is multi-dimensional, it will attempt to detect keyed vs ordered and build XML accordingly * * @param array associative array * @param string root element * @return string XML String */ public static function assoc2xml($assoc, $root_element = "xml") { if (!is_array($assoc) || count($assoc) == 0) { return "<" . $root_element . " />\n"; } foreach ($assoc as $key => $value) { if ($value === YES) { $value = "true"; } else { if ($value === NO) { $value = "false"; } else { if (!is_array($value) && strlen($value) == 0) { $xml .= "<" . $key . " />\n"; continue; } else { if (is_array($value)) { if (arr::is_assoc($value)) { $xml .= xml::assoc2xml($value, $key); } else { $xml .= xml::ordered2xml($value, $key); } continue; } else { if (self::use_cdata($value)) { $value = "<![CDATA[" . $value . "]]>"; } else { $value = htmlentities($value); } } } } } $xml .= "<" . $key . ">" . $value . "</" . $key . ">\n"; } return "<" . $root_element . ">\n" . xml::pad($xml) . "</" . $root_element . ">\n"; }
/** * Return a compiled string for this export data type * * @return string */ public function to_string() { return xml::ordered2xml($this->rows, $this->container); }