title: Add An XML Declaration To String Of XML
body: <p>I have some xml data that looks like..</p>
  
  <pre><code>&lt;Root&gt;
  &lt;Data&gt;Nack&lt;/Data&gt;
  &lt;Data&gt;Nelly&lt;/Data&gt;
  &lt;/Root&gt;
  </code></pre>
  
  <p>I want to add <code>"&lt;?xml version=\"1.0\"?&gt;"</code>  to this string. Then preserve the xml as a string.</p>
  
  <p>I attempted a few things..</p>
  
  <p>This breaks and loses the original xml string</p>
  
  <pre><code>myOriginalXml="&lt;?xml version=\"1.0\"?&gt;"  + myOriginalXml;
  </code></pre>
  
  <p>This doesnt do anything, just keeps the original xml data with no declaration attached.</p>
  
  <pre><code> XmlDocument doc = new XmlDocument();
                  doc.LoadXml(myOriginalXml);
                  XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8","no");
                  StringWriter sw = new StringWriter();
                  XmlTextWriter tx = new XmlTextWriter(sw);
                  doc.WriteTo(tx);
                  string xmlString = sw.ToString();
  </code></pre>
  
  <p>This is also not seeming to have any effect..</p>
  
  <pre><code>  XmlDocument doc = new XmlDocument();
                  doc.LoadXml(myOriginalXml);
                  XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "no");
                  MemoryStream xmlStream = new MemoryStream();
                  doc.Save(xmlStream);
                  xmlStream.Flush();
                  xmlStream.Position = 0;
                  doc.Load(xmlStream);
                  StringWriter sw = new StringWriter();
                  XmlTextWriter tx = new XmlTextWriter(sw);
                  doc.WriteTo(tx);
                  string xmlString = sw.ToString();
  </code></pre>