tags:

views:

94

answers:

3
+2  Q: 

XML Data Structure

Which one of two XML structures below do you prefer? Why? Any other suggestion is welcome :)

<Parameters>
  <Parameter id=username>metdos</Parameter>
  <Parameter id=password>123</Parameter>
</Parameters>

or

<Parameters>
  <username>metdos</username>
  <password>123</password>
</Parameters>
+2  A: 

The second one because it is more in line with what XML is supposed to be. However, if you really need to use the first one then it should be something like

<Parameter id="username" value="metdos" />

Raj
"XML is supposed to be":Why? Are there any source which declares it?
metdos
+2  A: 

It depends on the context of what you are trying to achieve. In general, I would prefer the second structure. It is well defined and easy to understand.

However, the first structure would be useful for scenarios where you don't know what parameters you will be supporting ahead of time or where you don't want your schema to change when additional parameters are introduced.

Tuzo
+4  A: 

Although the design of an XML structure may be a matter of preference, I like the second one. Your question seems to be one that has been discussed many times. The following links should be of help.

Garett
Yes, they helped a lot, thanks.
metdos