title: Should I use Elements or Attributes in XML?
body: <p>I am learning about <a href="http://www.w3schools.com/xml/xml_attributes.asp" rel="noreferrer">XML Attributes from W3Schools</a>.</p>
  
  <p>The author mentions the following (emphasis mine):</p>
  
  <blockquote>
    <h2>XML Elements vs. Attributes</h2>
  
  <pre><code>&lt;person sex="female"&gt;
    &lt;firstname&gt;Anna&lt;/firstname&gt;
    &lt;lastname&gt;Smith&lt;/lastname&gt;
  &lt;/person&gt;
  </code></pre>
    
    <hr>
  
  <pre><code>&lt;person&gt;
    &lt;sex&gt;female&lt;/sex&gt;
    &lt;firstname&gt;Anna&lt;/firstname&gt;
    &lt;lastname&gt;Smith&lt;/lastname&gt;
  &lt;/person&gt;
  </code></pre>
    
    <p>In the first example sex is an attribute. In the last, sex is an element. Both examples provide the same information.</p>
    
    <p>There are no rules about when to use attributes and when to use elements. Attributes are handy in HTML. <strong>In XML my advice is to avoid them. Use elements instead.</strong>  </p>
    
    <h2>Avoid XML Attributes?</h2>
    
    <p>Some of the problems with using attributes are:</p>
    
    <ul>
    <li>attributes cannot contain multiple values (elements can)</li>
    <li>attributes cannot contain tree structures (elements can)</li>
    <li>attributes are not easily expandable (for future changes)</li>
    </ul>
    
    <p><strong>Attributes are difficult to read and maintain. Use elements for data. Use attributes for information that is not relevant to the data.</strong></p>
  </blockquote>
  
  <p>So is the view of the author a famous one, or is this the best practice in XML?</p>
  
  <p>Should Attributes in XML be avoided?</p>
  
  <p>W3Schools also mentioned the following (emphasis mine):  </p>
  
  <blockquote>
    <h2>XML Attributes for Metadata</h2>
    
    <p>Sometimes ID references are assigned to elements. These IDs can be used to identify XML elements in much the same way as the ID attribute in HTML. This example demonstrates this:</p>
  
  <pre><code>&lt;messages&gt;
    &lt;note id="501"&gt;
      &lt;to&gt;Tove&lt;/to&gt;
      &lt;from&gt;Jani&lt;/from&gt;
      &lt;heading&gt;Reminder&lt;/heading&gt;
      &lt;body&gt;Don't forget me this weekend!&lt;/body&gt;
    &lt;/note&gt;
    &lt;note id="502"&gt;
      &lt;to&gt;Jani&lt;/to&gt;
      &lt;from&gt;Tove&lt;/from&gt;
      &lt;heading&gt;Re: Reminder&lt;/heading&gt;
      &lt;body&gt;I will not&lt;/body&gt;
    &lt;/note&gt;
  &lt;/messages&gt;
  </code></pre>
    
    <p>The ID above is just an identifier, to identify the different notes. It is not a part of the note itself.</p>
    
    <p><strong>What I'm trying to say here is that metadata (data about data) should be stored as attributes, and that data itself should be stored as elements.</strong></p>
  </blockquote>