We know XML documents are structured as hierarchies of information.We can easily convert xml into string using xmltextwriter.
C# Code:
string Convertedstring = null;
MemoryStream ms = new MemoryStream();
XmlSerializer xmlS = null;
xmlS = new XmlSerializer (inputxml.GetType());
XmlTextWriter tw = new XmlTextWriter (ms,EnCoding.UTF8);
xmlS.Serialize(tw,inputxml);
ms = (MemoryStream) tw.BaseStream;
//Converting ms to string
string Convertedstring = System.Text.Encoding.GetEncoding(“utf-8″).GetString(ms.ToArray());
Hope this helps,
Happy Coding.
Comments are closed.