September 25th, 2013, 06:28 AM
I'm new to XML and I've been reading about elements vs. attributes.
In a case like:
Would it be possible to express the same information, without using any attribute keys. Would it be correct:
Thank you very much in advance!
October 1st, 2013, 07:07 AM
well usage of attributes or elements is usually decided by the data you are trying to model.
certain entity is PART of the data, then it is advisable to make it an element.
Hope this helps.
October 1st, 2013, 01:25 PM
The first and third ones have the same data but expressed differently so they're both fine - as priyankagound said it comes down to the model you have to follow.
The second one isn't good because now somebody has to parse the "9 cm" string to get the length and units. They might have to deal with "9cm" or "9 CM" or some other format that can arise from making something a text field.
In general with XML you want to break down the data into as many individual components as you can: keep the "9" separate from the "cm". Whether you use attributes or elements isn't as important.