Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save szeidler/76533a3fb6684eadcd847227a0739998 to your computer and use it in GitHub Desktop.
Save szeidler/76533a3fb6684eadcd847227a0739998 to your computer and use it in GitHub Desktop.
Add support for index values on xml output. Otherwise you will lose information about numeric array keys.
diff --git a/servers/rest_server/includes/ServicesFormatter.inc b/servers/rest_server/includes/ServicesFormatter.inc
index 9799b19..8ce275a 100644
--- a/servers/rest_server/includes/ServicesFormatter.inc
+++ b/servers/rest_server/includes/ServicesFormatter.inc
@@ -61,6 +61,7 @@ class ServicesXMLFormatter implements ServicesFormatterInterface {
$assoc = FALSE || empty($data);
foreach ($data as $key => $value) {
if (is_numeric($key)) {
+ $id = $key;
$key = 'item';
}
else {
@@ -69,6 +70,9 @@ class ServicesXMLFormatter implements ServicesFormatterInterface {
$key = preg_replace('/^([0-9]+)/', '_$1', $key);
}
$element = $doc->createElement($key);
+ if (isset($id)) {
+ $element->setAttribute('id', $id);
+ }
$parent->appendChild($element);
$this->xml_recursive($doc, $element, $value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment