Closed (fixed)
Project:
Services
Version:
7.x-3.1
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
18 May 2012 at 06:43 UTC
Updated:
31 Aug 2012 at 09:21 UTC
Jump to comment: Most recent
I am currently working on a resource for my application. As different formats (JSON/XML) should be presented in identical structures, i am now struggling with the given root element "<result>" of the render_xml-method in rest_server.views.inc.
The specification needs to create a response like this
<?xml version="1.0" encoding="utf-8"?>
<service_definition>
<service_code>DMV66</service_code>
<attributes>
etc ...
Is there a way to override this function? Or maybe something like this would be a good solution for always applying the first key of the data-array as root-element:
private function render_xml($data) {
$doc = new DOMDocument('1.0', 'utf-8');
// $root = $doc->createElement('result');
$root = $doc->createElement(key($data));
$doc->appendChild($root);
// shifting all children to top-level
$data = $data[key($data)];
// deleting first key
unset($data[key($data)]);
$this->xml_recurse($doc, $root, $data);
return $doc->saveXML();
}
Any other ideas very much appreciated ...
Comments
Comment #1
markaspot commentedComment #2
ygerasimov commentedI wouldn't like to change this as this is big API change and current clients will break.
If your specifications require these changes, I would suggest to alter formatters and have your own custom function to prepare output for XML.
Please reopen this ticket if you have any further questions.
Comment #4
markaspot commentedthanks for the reply .. i will try to implement hook_services_request_postprocess_alter
Comment #4.0
markaspot commentedadded some code to render_xml ...
Comment #5
jeroen.b commentedI also had this problem. My XML had to match some XSD provided by another company.
The way I did this was with a custom formatter.