Formats XML elements.
$array: An array where each item represents an element and is either a:
In both cases, 'value' can be a simple string, or it can be another array with the same format as $array itself for nesting.
If 'encoded' is TRUE it is up to the caller to ensure that 'value' is either entity-encoded or CDATA-escaped. Using this option is not recommended when working with untrusted user input, since failing to escape the data correctly has security implications.
function format_xml_elements($array) {
$output = '';
foreach ($array as $key => $value) {
if (is_numeric($key)) {
if ($value['key']) {
$output .= ' <' . $value['key'];
if (isset($value['attributes']) && is_array($value['attributes'])) {
$output .= drupal_attributes($value['attributes']);
}
if (isset($value['value']) && $value['value'] != '') {
$output .= '>' . (is_array($value['value']) ? format_xml_elements($value['value']) : (!empty($value['encoded']) ? $value['value'] : check_plain($value['value']))) . '</' . $value['key'] . ">\n";
}
else {
$output .= " />\n";
}
}
}
else {
$output .= ' <' . $key . '>' . (is_array($value) ? format_xml_elements($value) : check_plain($value)) . "</{$key}>\n";
}
}
return $output;
}