title: Serialize XmlDocument & send via HTTPWebRequest
body: <p>I'm trying to figure out how to properly serialize my XmlDocument and send it via a HTTPWebRequest object.</p>
  <p>Here's what I have thus far:</p>
  <pre><code>Stream requestStream;
  
  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(&quot;https://wwwcie.ups.com/ups.app/xml/Track&quot;);
  request.Method = &quot;POST&quot;;
  
  request.ContentType = &quot;application/x-www-form-urlencoded&quot;;
  request.ContentLength = postData.Length;
  requestStream = request.GetRequestStream();
  
  XmlSerializerNamespaces xsm = new XmlSerializerNamespaces();
  xsm.Add(&quot;&quot;, &quot;&quot;); // remove namespace
  XmlSerializer ser = new XmlSerializer(xmlRequest.GetType());
  ser.Serialize(requestStream, xmlRequest);
  
  requestStream.Write(postData, 0, postData.Length);
  requestStream.Close();
  </code></pre>
  <p>A few things I'm uncertain about. I have 2 XmlDocuments I need to send in the same HTTPWebRequest. I've tried before to convert the XmlDocuments to strings and just concatenate them (to send the string) but when I used the StringBuilder / Writer it adds:</p>
  <pre><code>  &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt; 
    &lt;string xmlns=&quot;http://myNameSpace/&quot;&gt;
  </code></pre>
  <p>I already have the declaration in my XmlDocument objects so now its in there twice, and I cannot have the <code>&lt;string...</code> part in there. Is it easier to convert the XmlDocuments to strings then concatenate them and send that or is there a easy way to send the XmlDocuments as they are?</p>
  <p><strong>Edit:</strong></p>
  <p>See <a href="https://stackoverflow.com/questions/1104549/c-xmldocument-nodes">C# XmlDocument Nodes</a>
  When I try to convert one of my XmlDocuments to a string it shows up as</p>
  <pre><code>  &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt; 
    &lt;string xmlns=&quot;http://myNamespace/&quot;&gt;
        &lt;TrackRequest&gt;
           &lt;Request&gt;
              &lt;TransactionReference&gt;
                  &lt;CustomerContext&gt;whatever&lt;/CustomerContext&gt;
              &lt;/TransactionReference&gt;
           &lt;/Request&gt;
           &lt;TrackingNumber&gt;123&lt;/TrackingNumber&gt;
        &lt;/TrackRequest&gt;
     &lt;/string&gt; 
  </code></pre>
  <p>I want my root to be <code>&lt;TrackRequest&gt;</code></p>