I ran into a bit of a road block when I had a complex XML code structure already already typed as a string. I didn’t have the time to convert the entire string (which contained well formatted XML) into an XMLDocument structure. However, I needed my Web Service to return true XML in the form of an XMLDocument. So…. here is how I did it.
public XmlDocument ExampleWS()
XmlDocument xDoc = new XmlDocument();
string xmlAsString = @"
// --- magical two lines of code, run in the string as a Memory Stream
// --- thus making XMLDoc think it is a file containing XML!
byte byteArray = Encoding.ASCII.GetBytes(xmlAsString);
MemoryStream stream = new MemoryStream(byteArray);