tags:

views:

115

answers:

5

Possible Duplicates:
How to design storing complex object settings in an xml
XML attribute vs XML element

What's the criteria to use when deciding whether something should be done like this:

<Blur Type="Gaussian", Amount=5></Blur>

or

<Blur>Gaussian, 5</Blur>

If it's #1, then what would you put inside the brackets?

Also I don't know what values inside the brackets are called (Gaussian, 5): inside properties?

+2  A: 

used

<Blur Type="Gaussian" Amount="5"/>

these are called attributes,

inside iscalled the value of the node

astander
+2  A: 

It really depends on how the XML is going to be used. My general rule of thumb is:

  • For simple types (int, double, string, datetime) use attributes.
  • For complex types, use child elements.
siz
+5  A: 
  1. The values inside the XML tags are called tag values.

  2. Your second example is an example of how NOT to structure XML (in general, for any data storage, XML included, you don't want to bundle >1 attribute value into one blob, unless you are forever guaranteed that the 2 values will never be used/queried separately and that performance benefits of bundling are significant).

    It should instead be

<Blur>
 <Type>Gaussian</Type>
 <Amount>5</Amount>
</Blur>

The choice between the two is sometimes blurred, but a very good set of guidelines exists from IBM

DVK
fwiw, re: point 1, they're called "attributes"
annakata
+3  A: 

Ok, first of all the first form isn't XML with that comma and without quotes.

Secondly, you're talking about attributes vs child elements and this is already covered here, here, here and many times over elsewhere.

Finally, door #2 is not a data structure of any reasonable kind anyway. Generally: use attributes where the relationship is meta-data, use child elements where the relationship is composition.

annakata
-1 *for what?*
annakata
Not sure why this got voted down as it seemed a very sensible answer...
Brian Agnew
Thanks anna, I gave +1.
Joan Venge
A: 

I would think it depends on personal preference, if you prefer:

<blur>
    <type>Gaussian</type>
    <amount>5</amount>
</blur>

or

<blur type="Gaussian" amount="5" />

Which ever makes your parsing more effortless for yourself. Sometimes it is easier to reference children rather than attributes, that obviously depends on which language you will be using for parsing.

Anriëtte Combrink