views:

26

answers:

2

Hash.to_xml and other such Railsisms may result in element orderings being different in the output of a REST service. XML Elems are order sensitive, so this would not be a problem for JSON or XML attributes.

What aspect of service definition best practices is this breaking that makes me think it is a smell ??

A: 

non-deterministic ordering would be my expectation -- meaning, that I would not depend on anything else.

It's nice if you can provide a deterministic XML for simple diffing, but that's more in static XML then in service responses.

Lou Franco
Can you cite on what you have based that expectation ? I've heard that expectation before, justified by the fact that in ruby {:x=>1, :b=>2}.to_xml may come out in any order
Dean Radcliffe
It's not just that -- XML is specifically not order dependent. There is nothing in XML schema definitions or XSD's that let's you say that your nodes need to be in an order -- therefore, order just has no meaning in XML. The same is true for attributes in a node. These aspects of XML is what sets my expectation.
Lou Franco
Lou, to refute one of your points: http://www.w3schools.com/schema/el_sequence.asp (this allows you to say your nodes must appear in an order). Also the xml spec (http://www.w3.org/TR/REC-xml/) agrees that attributes' order is insignificant, but nothing in the spec indicates that the same is true for elements, in fact the existence of the xs:sequence element in schema (and no corresponding one for attributes) refutes the second part of your claim.
Dean Radcliffe
+1  A: 

Thinking of REST over HTTP, caching is a big leverage. Even if the inside is "semantically" the same, if it differs structurally then you could end up with a lot of Cache misses (e.g. done with ETags). Of course it depends "how" the comparison is done, but imho most Cache implementations use simple hashing of the returned payload as comparing-entity.

So if Caching is important, I would tend to spit out also same structure for "semantically" same documents.

manuel aldana