Voters make better lovers! Login and vote now.
By o_sam_o
via java.dzone.com
Published: Jul 03 2008 / 04:30
By o_sam_o
via java.dzone.com
Published: Jul 03 2008 / 04:30
Comments
aj16780 replied ago:
Don'ts:
"Having Elements That Only Contain Attributes"
"Not Wrapping Repeated Elements"
What a BS.
Articles take less space than elements with their close tags. They are also meant to define properties that element can only have once. Elements should be used only when there can be multiple contained values.
Of course if you write your examples in different ways, one might look nicer.
Which one is better:
<artist
type="band"
name="Arcade Fire"
country="Canada"
/>
<artist><type>band</type><name>Arcade Fire</name><country>Canada</country></artist>
And wrapping elements is hideous. That's why XML has sequences. And think about the mess in object mapping.
Whole article is badly written.
"Why is this better? Firstly, it's the way it was intended"
According to whom?
o_sam_o replied ago:
I do have a reference link in there which states:
"Attributes are designed for expressing simple properties of the information represented in an element." http://www.ibm.com/developerworks/xml/library/x-eleatt.html
When to use attributes is very subjective, i personally think they should be used sparingly.
All XML readers i have used would style the XML in the way I've presented it, i haven't seen any that would style them in the way you have it. I will conceded that wrapper elements can cause nasty object models, however, JAXB now caters for this with the XmlElementWrapper annotation.
dragmire replied ago:
I completely disagree with:
Having Elements That Only Contain Attributes - There are cases where having only attributes is completely valid. I wouldn't restrict the tool to even more tagging. XML is hard enough to read as is.
Repeating Elements Names in Different Contexts - As long as the different elements are on different levels of the hierarchy, there shouldn't be an issue. Quit reading XML like HTML.
Otherwise, I agree with the rest.
Voters For This Link (22)
Voters Against This Link (2)