Which would be the correct format for this XML data, are they equivalent or are there trade offs between the two?
1.
<sitemap> <category name='Animals'> <section title='Dogs'> <page url='/pics/greatdane.jpg' title='Great Dane'/> </section> </category> </sitemap>
2.
<sitemap> <page> <category>Animals</category> <section>Dogs</section> <title>Great Dane</title> <url>/pics/greatdane.jpg</url> </page> </sitemap>
I’ve implemented the first example with my style sheet and it seems to work fine, but I’m unsure what the correct form should be.
The issue of attributes vs elements has been around for the better part of a decade and there is no right answer. Instead consider the differences and from that you should be able to decide which to use:
Attributes lead to a more concise syntax if there are no children. Compare:
<page name=’Sitemap’/>
to:
I know which one I prefer;
So, from your example, your innermost
<page>element has a URL attribute (although it’s an image for some reason–perhaps a preview icon? If so the attribute name is misleading). A webpage only has one URL (generally) so that’d be a good example of something that could be an attribute.If on the other hand you wanted to list the images on the page, there could obviously be more than one so you’d need elements for that.
But, in the end, most of the time there’s no right or wrong answer and it’s largely a question of style.