title: Adding attribute to existing XMLNodes
body: <p>Hi I am trying to add an attribut to several tags in an existing xml file.Here is the xml structure:</p>
  
  <pre><code>&lt;Planet&gt;
    &lt;Continent ContinentName="Africa"&gt;
      &lt;Country CountryName="Algeria" /&gt;
      &lt;Country CountryName="Angola" /&gt;
       ...
    &lt;/Continent&gt;
    &lt;Continent ContinentName="Europe"&gt;
      &lt;Country CountryName="France" /&gt;
      &lt;Country CountryName="England" /&gt;
      ...
    &lt;/Continent&gt;
    ...
  &lt;/Planet&gt;
  </code></pre>
  
  <p>I am trying to add an Id attribut to each of the country tags.Here is my code:</p>
  
  <pre><code>public static List&lt;Cities&gt; cities = new List&lt;Cities&gt;();
  
  XmlDocument xDoc = new XmlDocument();
  xDoc.Load(@"D:\Projects IDE\Visual Studio\Tutorial\e-commerce\classModeling\GenerateXml file\GenerateXml file\bin\Debug\Planet.xml");
  XmlAttribute xKey = xDoc.CreateAttribute("Id");
  XmlElement root = xDoc.DocumentElement;
  XmlNodeList nodes = root.SelectNodes("//Country");
  int count = 0;
  
  foreach( XmlNode node in nodes ) {
      string name = node.Attributes["CountryName"].Value;
  
      foreach (var cityObj in cities)
      {
          xKey.Value = cityObj.cityInitial;
  
          if(name == cityObj.cityName)
          {
              count++;
              node.Attributes.Append(xKey);
              Console.WriteLine(count);
          }
      }
  
  }
  
  xDoc.Save(@"D:\Projects IDE\Visual Studio\Tutorial\e-commerce\classModeling\GenerateXml file\GenerateXml file\bin\Debug\Planets.xml");
  </code></pre>
  
  <p>The problems is that this code only adds the id to the last element in the XML file.
  Now at first I tought that's because only one condition is true but then I added a counter and it turns out that that condition is true 179 times.If that is the case why am I getting only one attributt added at the finish?</p>