Using json output works just fine, but since xml cannot contain blank name tags it seems to just crap. I am not sure what would be the preferred method to handle this. Perhaps a warning in the output, ignore blank keyed items, or replace the blank string for something else like "blank" (not proper output of course).
Either way a completely blank result seems like a bad way to handle it. If anything just print "data structure is not compatible with output format. see ...some page that explains it".
The easiest way to recreate is to use the node/retrieve action and modify the code in rest_server.views.inc as follows.
private function render_xml($data) {
$doc = new DOMDocument('1.0', 'utf-8');
$root = $doc->createElement('result');
$doc->appendChild($root);
$data->array[''] = 'foo'; // add this
$this->xml_recurse($doc, $root, $data);
return $doc->saveXML();
}
I had this happen as a field serializes it's data and ends up with a blank string as one of the keys (which is completely valid usecase).
Comments
Comment #1
ygerasimov commented@boombatower can you advise when do you get structure with empty key? I understand that you can recreate it with custom code, but can you advise real life example?
In node retrieve I think all properties will have non-empty keys.
Comment #2
boombatower commentedThe code the triggerd the above comes form the revamped qa.d.o code (simple example to recreate above). In the code we map paths (which can be blank) to some value. In that case when the structure is exported it blows up when using XML.
Obviously, a minor thing, but given that I saw an issue about google returning ->$t (fun for php users and odd in general) as property name in their services I can only image what seemingly odd things people do. If not something you want to support perhaps some sort of non-catastrophic fallback or warning to explain what is going on.
Comment #3
ygerasimov commentedTruly to say in this case I would simply raise exception and drop error message that XML cannot be properly formatted as there is value key that is empty. We should not be keep silence and send irrelevant formatted XML. @boombatower, do you think it is way to go?
Comment #4
boombatower commentedYea, some sort of message so people can figure what is going on (probably even suggest using different format like json). The data structure cannot be formatted in XML without altering so an error makes sense.
Comment #5
kylebrowning commentedCan you provide a patch maybe with how you this should be done? Im not entirely certain whats happening.
Comment #6
boombatower commentedTry to export a data structure with a blank string key. I was using a custom field, but you can manually tweak a node object or some such if you wantsimplest alter a node before output to recreate in the simplest.
Comment #7
kylebrowning commentedWe reworked the xml output formatter a bit and this has been fixed.