title: Append Multiple Similar XML Nodes to XML Document
body: <p>I'm currently working with an XML request, and am trying to create a Reply Document that has multiple child nodes of the same name in the call, so what I'm trying to return is: </p>
  
  <pre><code>&lt;Reply Document&gt;
      &lt;ConfirmationItem name = "One"&gt;
           &lt;ItemDetail /&gt;
      &lt;/ConfirmationItem&gt;
      &lt;ConfirmationItem name = "Two"&gt;
           &lt;ItemDetail /&gt;
      &lt;/ConfirmationItem&gt;
      ...
      &lt;ConfirmationItem name = "Twenty"&gt;
           &lt;ItemDetail /&gt;
      &lt;/ConfirmationItem&gt;
  &lt;/Reply Document&gt; 
  </code></pre>
  
  <p>I did a bit of research and found this thread: <a href="https://stackoverflow.com/questions/659034/xmlreader-appendchild-is-not-appending-same-child-value">XmlReader AppendChild is not appending same child value</a>  in which the accepted answer was that the OP had to create new Elements to be able to append to the end instead of overwrite the first.  </p>
  
  <p>My original code is below, it creates the XmlNode from the incoming Request and appends the result to the XmlDocument itself: </p>
  
  <pre><code>//p_transdoc is the XmlDocument that holds all the items to process.  
  XmlNodeList nodelst_cnfrm = p_transdoc.SelectNodes("//OrderRequest");
  foreach (XmlNode node in nodelst_cnfrm)
  {
       //this is just an XML Object 
       XmlNode node_cnfrm_itm = this.CreateElement("ConfirmationItem");
       node_cnfrm_itm.Attributes.Append(this.CreateAttribute("name")).InnerText = p_transdoc.Attributes["name"].InnerText;
  
       XmlNode node_itmdtl = this.CreateElement("ItemDetail");
       node_cnfrm_itm.AppendChild(node_itmdtl);
  //xml_doc is the return XML request                    
  xml_doc.AppendChild(node_cnfrm_itm);
  }
  </code></pre>
  
  <p>So after reading that thread and the answer, I tried to change the code to use a new XmlElement each pass through.          </p>
  
  <pre><code>//p_transdoc is the XmlDocument that holds all the items to process.  
  XmlNodeList nodelst_cnfrm = p_transdoc.SelectNodes("//OrderRequest");
  foreach (XmlNode node in nodelst_cnfrm)
  {
       XmlElement node_cnfrm_itm = new XmlElement();
       node_cnfrm_itm = this.CreateElement("ConfirmationItem");
       node_cnfrm_itm.Attributes.Append(this.CreateAttribute("name")).InnerText = p_transdoc.Attributes["name"].InnerText;
  
       XmlElement node_itmdtl = new XmlElement();
       node_itmdtl = this.CreateElement("ItemDetail");
       node_cnfrm_itm.AppendChild(node_itmdtl);
       //xml_doc is the return XML request                    
       xml_doc.AppendChild(node_cnfrm_itm);
  }   
  </code></pre>
  
  <p>But not only does that not work, it returns a server error.  So I've come to you for help.  Right now this code is just returning one ConfirmationItem.  How would I be able to append the ConfirmationItem to the end of the Document instead of overwrite it, to be able to return as many as were sent in?</p>
  
  <p>(I should point out that this code has been heavily formatted for ease of readability, simplicity, and to reduce clutter. Any typographical errors are purely because of the Asker's internal failure at effective proofreading). </p>