xml format c# code example
Example: c sharp xml prettier
public static string PrintXML(string xml)
{
string result = "";
MemoryStream mStream = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(mStream, Encoding.Unicode);
XmlDocument document = new XmlDocument();
try
{
document.LoadXml(xml);
writer.Formatting = Formatting.Indented;
document.WriteContentTo(writer);
writer.Flush();
mStream.Flush();
mStream.Position = 0;
StreamReader sReader = new StreamReader(mStream);
string formattedXml = sReader.ReadToEnd();
result = formattedXml;
}
catch (XmlException)
{
}
mStream.Close();
writer.Close();
return result;
}