title: Iterate through each XElement in an XDocument
body: <p>I have an XML that looks like this:</p>
  
  <pre><code>&lt;myVal&gt;One&lt;/myVal&gt;
  &lt;myVal&gt;Two&lt;/myVal&gt;
  &lt;myVal&gt;Three&lt;/myVal&gt;
  &lt;myVal&gt;Four&lt;/myVal&gt;
  &lt;myVal&gt;Five&lt;/myVal&gt;
  </code></pre>
  
  <p>I want to load that into an XDocument and then iterate through each XElement in that XDocument and count the number of characters in each element.</p>
  
  <p>What is the best way of doing that?</p>
  
  <p>First off, I noticed I have to add a root element or XDocument.Parse() would not be able to parse it as XML. So I added: </p>
  
  <pre><code>&lt;span&gt;
          &lt;myVal&gt;One&lt;/myVal&gt;
          &lt;myVal&gt;Two&lt;/myVal&gt;
          &lt;myVal&gt;Three&lt;/myVal&gt;
          &lt;myVal&gt;Four&lt;/myVal&gt;
          &lt;myVal&gt;Five&lt;/myVal&gt;
  &lt;/span&gt;
  </code></pre>
  
  <p>But then when I do: </p>
  
  <pre><code>foreach (XElement el in xDoc.Descendants())
  </code></pre>
  
  <p><code>el</code> will contain the entire XML, starting with the first <code>&lt;span&gt;</code>, including each and every one of the <code>&lt;myVal&gt;</code>s and then ending with <code>&lt;/span&gt;</code>.</p>
  
  <p>How do I iterate through each of the XML elements (<code>&lt;myVal&gt;One&lt;/myVal&gt;</code> etc) using XDocument?</p>
  
  <p>I don't know on beforehand what all the XML elements will be named, so they will not always be named "myVal".</p>