title: adding additional tags to existing XML file
body: <p>I have an xml file which contains the following structure</p>
  
  <pre><code>   &lt;Planet&gt;
        &lt;Continent name="Africa"&gt;
          &lt;Country name="Algeria" /&gt;
          &lt;Country name="Angola" /&gt;
            ...
        &lt;/Continent&gt;
      &lt;/Planet&gt;
  </code></pre>
  
  <p>I need to add to it the rest of the continent tags with there containing cities.
  This is my code:</p>
  
  <pre><code>       public static string continent;
         public static List&lt;string&gt; countries = new List&lt;string&gt;();
  
         XmlDocument xDoc = new XmlDocument();
         xDoc.Load(@"D:\Projects IDE\Visual Studio\Tutorial\e-commerce\classModeling\GenerateXml file\GenerateXml file\bin\Debug\Planet.xml");
  
          XmlNode xNode = xDoc.CreateNode(XmlNodeType.Element, "Continent", "");
          XmlAttribute xKey = xDoc.CreateAttribute("name");
          xKey.Value = continent;
          xNode.Attributes.Append(xKey);
          xDoc.GetElementsByTagName("Planet")[0].InsertAfter(xNode , xDoc.GetElementsByTagName("Planet")[0].LastChild);
  
  
          foreach (var country in countries)
          {
              XmlElement root = xDoc.CreateElement("Country");
              XmlAttribute xsKey = xDoc.CreateAttribute("name");
              xsKey.Value = country;
              root.Attributes.Append(xKey);
  
          }     
          xDoc.Save(@"D:\Projects IDE\Visual Studio\Tutorial\e-commerce\classModeling\GenerateXml file\GenerateXml file\bin\Debug\Planet.xml");    
  </code></pre>
  
  <p>My code creates all the tags but does not add the attributes.</p>
  
  <p>And before anyone asks the continent variable and countries list contain the needed items I just felt it's not needed to display that part of the code two.</p>
  
  <p>What am I doing wrong here?       </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I managed to corect the code and now it work the attributes were not apearing because I gave both the the node attribute and element attribute the same name I changd the names , and now it works.                                      </p>