all groups > dotnet xml > june 2005 >
You're in the

dotnet xml

group:

Element or Attribute, which one should I use. thanks!


Element or Attribute, which one should I use. thanks! davidw
6/26/2005 9:37:50 PM
dotnet xml: I need store some setting in XML. I can not decide to use xml element or xml
attribute to store them, for example, the XML could be

<Page>
<Label>test</Label>
<Size>10</Size>
.....
</Page>

and it could be
<Page label="test" size="10"/>

I read some articles. Most them suggest element, the first one. But in my
experience, attribute is more easy to handle, no matter edit it manually or
read them in code. And sitemap of .NET 2.0 uses this format too.

Any suggestion?

Thanks!

Re: Element or Attribute, which one should I use. thanks! Oleg Tkachenko [MVP]
6/27/2005 11:55:34 AM
[quoted text, click to view]

Actually there is no right answer. Use whatever appropriate. For atomic
properties - attributes, for (even potentially) complex (or ordered)
data with - elements. If you sure that you never decide that Label
should contain other markup - make it attribute, otherwise element is a
safer choice.

--
Oleg Tkachenko [XML MVP, MCAD]
AddThis Social Bookmark Button