title: Sort XmlDocument by attribute using C#
body: <p>I have an XmlDocument that looks something like this;</p>
  
  <pre><code>&lt;Root&gt;
    &lt;file id="1" amount="10" att="0" /&gt;
    &lt;file id="2" amount="20" att="0"/&gt;
    &lt;file id="3" amount="40" att="0"/&gt;
    &lt;file id="4" amount="30" att="0"/&gt;
    &lt;file id="5" amount="10" att="0"/&gt;
  &lt;/Root&gt;
  </code></pre>
  
  <p>After sort, it should look like this:</p>
  
  <pre><code>&lt;Root&gt;
    &lt;file id="3" amount="40" att="0"/&gt;
    &lt;file id="4" amount="30" att="0"/&gt;
    &lt;file id="2" amount="20" att="0"/&gt;
    &lt;file id="1" amount="10" att="0"/&gt;
    &lt;file id="5" amount="10" att="0"/&gt;
  &lt;/Root&gt;
  </code></pre>
  
  <p>I generate an XmlDocument;</p>
  
  <pre><code>XmlDocument xDoc = new XmlDocument();
  </code></pre>
  
  <p>I then generate an XmlNodeList;</p>
  
  <pre><code>XmlNodeList xAmount = xDoc.SelectNodes("Root/file[@att='0']");
  </code></pre>
  
  <p>I then do a for loop and build a multidimensional array.</p>
  
  <pre><code>amtArray = new int[xAmount.Count, 2];
  
  for (int i = 0; i &lt; xAmount.Count; i++)
  {
      amtArray[i,0] = xAmount[i].Attribute["id"].Value;
      amtArray[i,1] = xAmount[i].Attribute["amount"].Value;
  }
  </code></pre>
  
  <p>I can attempt a sort at any given point where possible.</p>
  
  <p>sort the whole XmlDocument, xDoc</p>
  
  <p>or</p>
  
  <p>sort the XmlNodeList, xAmount</p>
  
  <p>or</p>
  
  <p>sort the multidimensional array.</p>
  
  <p>I'm asking if there is a way to sort the whole XmlDocument or the XmlNodeList.</p>