Possible Duplicate:
XML attribute vs XML element
I’m creating an XML document that holds cinemas. I need a way to represent the facilities a certain cinema has, but am uncertain on how to structure it.
Should I have each facility as a node? And the text inside that node would either be a 1 or 0 (true of false)? Or would it be better to have each facility as an attribute or a “facilities” node?
Attributes:
<cinema id="1">
...
<facilities advance_screenings="1" concessions="0" ... >1<facilities>
</cinema>
Nodes:
<facilities>
<advance_screenings>1</advance_screenings>
<audio_description>1</audio_description>
<bar>1</bar>
<concessions>1</concessions>
...
</facilities>
Thanks.
This is largely a matter of preference/style.
However – there are some rules of thumb:
Non-primitive types must be elements (you are using the term “node”). You can’t have an attribute which represents a complex type – although you can do some pattern matching.
1000 attributes on a single element is probably not a great design – strive for human readability.
As a corollary to the above point, avoid 1000 elements as direct descendants of a single element. (Nest/group elements in a logical structure).
Having some feeling for what a “nice structure” is vs. a “bad structure” is a complicated judgement which takes a lot of factors into account – such as the industry/context in which the data is being used, and what it represents. It’s similar to class design or probably closer to database design. Sometimes a hack job won’t make one iota of difference – other times semantic precision is of primary importance.
You’ll only get a good grasp of it through experience.