Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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:</p> <ul> <li>There can be only one instance of an attribute although you can enforce this with elements using DTD or XML Schema;</li> <li>Attributes are unordered. Elements are not;</li> <li><p>Attributes lead to a more concise syntax if there are no children. Compare:</p> <p>&lt;page name="Sitemap"/></p></li> </ul> <p>to:</p> <pre><code>&lt;page&gt; &lt;name&gt;Sitemap&lt;/name&gt; &lt;/page&gt; </code></pre> <p>I know which one I prefer;</p> <ul> <li>Not really relevant now since DTDs aren't used much (if at all) over XML Schema but I'll add it anyway: DTDs allow default values (implied) for attributes but no such mechanism for elements; and</li> <li>Elements, being elementss, can have children and attributes of their own. Attributes obviously cannot.</li> </ul> <p>So, from your example, your innermost <code>&lt;page&gt;</code> 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.</p> <p>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.</p> <p>But, in the end, most of the time there's no right or wrong answer and it's largely a question of style.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload