title: Need help in adding a new XML node
body: <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;mappings&gt;
    &lt;mapping&gt;
      &lt;aID iskey="true"&gt;ABC&lt;/aID&gt;
      &lt;bID iskey="true"&gt;DEF&lt;/bID&gt;
      &lt;SubAccount&gt;PS&lt;/SubAccount&gt;
      &lt;Account&gt;PS&lt;/Account&gt;
    &lt;/mapping&gt;
    &lt;mapping&gt;
      &lt;aID isKey="true"&gt;GHI&lt;/aID&gt;
      &lt;bID isKey="true"&gt;PFP&lt;/bID&gt;
      &lt;SubAccount&gt;MS&lt;/SubAccount&gt;
      &lt;!-- I want to add a new node here, how can I do this  --&gt;
    &lt;/mapping&gt;
    &lt;mapping&gt;
      &lt;aID isKey="true"&gt;MNO&lt;/aID&gt;
      &lt;bID isKey="true"&gt;BBG&lt;/bID&gt;
      &lt;SubAccount&gt;MAX&lt;/SubAccount&gt;
    &lt;/mapping&gt;
  &lt;/mappings&gt;
  </code></pre>
  
  <p>I want to add a new node as mentioned in the above XML. I tried a lot but I could not succeed.</p>
  
  <pre><code>XmlDocument xDoc = new XmlDocument();
  xDoc.Load(filename);
  
  foreach (XmlNode node in xmlDoc.SelectNodes("/mappings/mapping"))
  {
      if (boothIDNode.InnerXml == BoothID)
      {
          chkBoothIDExists = true;
          if (clientIDNode.InnerText == ClientID)
          {
              chkClientIDExists = true;
              for (int j = 2; j &lt; nodelist.Count; j++)
              {
                  columnNode = nodelist[j];
                  if (columnNode.Name == column.ToString())
                  {
                      XmlNode elm = xDoc.CreateNode(XmlNodeType.Element,"Account",null);
                      elm.InnerText = value.ToString();                                                                                 
                      node.AppendChild(elm);  //  Error comes here 
                  }
              }
          }
      }   
  }
  
  xmlDoc.Save(filename);  
  </code></pre>
  
  <p>The question is solved. The problem occured due to my silly mistake. Basically there are two xml documnets and I'm creating a new node of other xml documnet due to which the error cames.
  THanks all, 
   XmlDocument xDoc = new XmlDocument();
    XmlDocument xmlDoc = new XmlDocument();</p>
  
  <p>ERROR: The node to be inserted is from a different document context</p>