After reading the "Idiot's Guide to XML", I was still confused about certain aspects of implementing XML.
Which is better to use?
<person name="John" surname="Doe"></person>
or
<person>
<name>John</name>
<surname>Doe</surname>
</person>
After reading the "Idiot's Guide to XML", I was still confused about certain aspects of implementing XML.
Which is better to use?
<person name="John" surname="Doe"></person>
or
<person>
<name>John</name>
<surname>Doe</surname>
</person>
I read the same book. Pretty bland
It's completely up to you, though. It may depend on how you want to use the data, which way makes more sense, or if you just want to use fewer characters. You could also user /> instead of the closing tag...
I'd say how you're planning to use the data should be your guide.
I think you should use elements for most things (especially properties of the parent element, like "name" for a "person"). IT seems to me that attributes are only useful if you want to make a distinction between instances of the same element, for example <phoneno type="home"> and <phoneno type="work">.
Sure, but if you're wanting to model a real-life object, such as a person, you (a person) have an attributes, one of which is your name. Your name isn't some sub-part of who you are, not the way a driver's license number or address would be. It may be a unique way to identify yourself, but unless you're up to no good you've only got one =).
That's another criteria for attribute vs. element. You can have more than one element of the same type, but only one attribute. So middlename would probably be an element, since some people out there have several.