I'm designing an API for a web service and I can't decide between using XML attributes, elements or a mixed architecture.
Let me show you an example. Let's assume I have an object called Domain. This model has 3 properties (tld
, sld
, trd
and the name
itself) and a method valid?
that returns true if the domain is valid.
# I'm using ruby but
# consider this as pseudo-code
class Domain
attr_accessor :tld, :sld, :trd, :name
def valid?
true # force true
end
end
My api called /domain/parser
takes a domain in input and returns the parsed response. The first possibility is to use an element for every domain attribute.
<result>
<domain>
<name>www.google.it</name>
<tld>it</tld>
...
<valid>true</true>
</domain>
</result>
But some interfaces use attributes.
<result>
<domain tld="it" sld="google.com" trd="www" rule="*.foo" name="www.google.it" valid="true" />
</result>
And don't forget attributes and value.
<result>
<domain tld="it" sld="google.com" trd="www" rule="*.foo" name="www.google.it" valid="true">
www.google.it
</domain>
</result>
In your opinion, which is the more powerful, flexible and expressive choice? Also, consider the response will be served in XML and JSON (soon).