xbezwukjiowicuehw
New Member
I have some xml data that looks like..\[code\]<Root><Data>Nack</Data><Data>Nelly</Data></Root>\[/code\]I want to add \[code\]"<?xml version=\"1.0\"?>"\[/code\] to this string. Then preserve the xml as a string.I attempted a few things..This breaks and loses the original xml string\[code\]myOriginalXml="<?xml version=\"1.0\"?>" + myOriginalXml;\[/code\]This doesnt do anything, just keeps the original xml data with no declaration attached.\[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\]This is also not seeming to have any effect..\[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\]