-
XML Document, HELP!
Hi,
I am a little confused about when you should use what. Here's an example:
Should I use this xml:
Code:
<person>
<name>shunt</name>
</person>
or should I use this xml:
Code:
<person name="shunt"/>
Can anyone tell me which one would be correct and why.
-
It depends on your requirements - if the person could have more than one name, you would need to use #1, so it really depends on your data model.
-
Attibutes are easier to use (shoter to write), and usually more clear.
But when you are planning to 'divide' the value or add extra options somewhere in the future it's better to use a child element right away.
Maybe sometime you want to be able to wite this:
Code:
<person>
<name>
John Johnes
</name>
<name>
<first-name>Bill</first-name>
<last-name>Gates</last-name>
</name>
</person>
You should also consider how you are going to edit these XML files. If you are using a text editor attributes have the benefit of being more readable. If you use some kind of XML editor, there is hardly any reason not to use child elements.
-
Also by going with attributes makes the file smaller.