title: Using C# to add an XML node to an exiting XML file
body: <p>I have an XML document that I am trying to modify...</p>
  
  <pre><code> &lt;fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"&gt;
    &lt;entity name="contact"&gt;
      &lt;attribute name="fullname" /&gt;
      &lt;attribute name="telephone1" /&gt;
      &lt;attribute name="contactid" /&gt;
      &lt;order attribute="fullname" descending="false" /&gt;
      &lt;filter type = "and"&gt;
        &lt;condition attribute="parentcustomerid" operator="eq" uiname="Tardis Communications" uitype="account" value="{BB0D0E64-C85E-E411-9405-00155D1DEA05}" /&gt;
      &lt;/filter&gt;
    &lt;/entity&gt;
  &lt;/fetch&gt;
  </code></pre>
  
  <p>What I am trying to do is insert this...</p>
  
  <pre><code>&lt;filter type = "and"&gt;
  &lt;condition attribute="ownerid" operator= "eq-userid"/&gt;
  &lt;/filter&gt;
  </code></pre>
  
  <p>in between the already existing "filter" tags. the new filter code is from another file (.txt). </p>
  
  <p>I realize that this may not make sense, however, I just want to see if it is possible. If so, I can move things around after.</p>
  
  <p>Here is what I tried. </p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
  {
      XmlDataDocument doc = new XmlDataDocument();
      doc.Load(@"C:\Users\jellsworth\Downloads\mySampleXML.xml");
      //XmlNode node = null;
      foreach (XmlNode node in doc.SelectNodes("//filter/condition")) 
      {
          XmlElement mapNode = doc.CreateElement("filter");
          XmlAttribute newFilter = doc.CreateAttribute("lattitude");
          newFilter.Value = @"C:\Users\jellsworth\Downloads\playFilter.txt";
          mapNode.SetAttributeNode(newFilter);
  
          node.InsertBefore(mapNode, node.FirstChild);
      }
  }
  </code></pre>
  
  <p>Any guidance would be greatly appreciated.</p>