home links tips
code users tools tutorials projects web help design
mudabone
suletzki trans48
nutrition reality
MarthaAttire!
| |
public string PrettyPrint(string XML) { String Result = "";
MemoryStream MS = new MemoryStream(); XmlTextWriter W = new XmlTextWriter(MS, Encoding.Unicode); XmlDocument D = new XmlDocument();
try { // Load the XmlDocument with the XML. D.LoadXml(XML);
W.Formatting = Formatting.Indented;
// Write the XML into a formatting XmlTextWriter D.WriteContentTo(W); W.Flush(); MS.Flush();
// Have to rewind the MemoryStream in order to read // its contents. MS.Position = 0;
// Read MemoryStream contents into a StreamReader. StreamReader SR = new StreamReader(MS);
// Extract the text from the StreamReader. String FormattedXML = SR.ReadToEnd();
Result = FormattedXML; } catch (XmlException) { }
MS.Close(); W.Close();
return Result; }
Comments:
Last Modified 3/19/04 1:58 PM
| Hide Tools
|
{
using( System.IO.MemoryStream MyMemoryStream = new System.IO.MemoryStream( ) ){
System.Xml.XmlTextWriter MyWriter = new System.Xml.XmlTextWriter(MyMemoryStream, System.Text.Encoding.Unicode);
System.Xml.XmlDocument MyDocument = new System.Xml.XmlDocument();
// Load the XmlDocument with the XML.
MyDocument.LoadXml(XML);
MyWriter.Formatting = System.Xml.Formatting.Indented;
// Write the XML into a formatting XmlTextWriter
MyDocument.WriteContentTo(MyWriter);
MyWriter.Flush();
MyMemoryStream.Flush();
// Have to rewind the MemoryStream in order to read
// its contents.
MyMemoryStream.Position = 0;
// Read MemoryStream contents into a StreamReader.
using( System.IO.StreamReader MyReader = new System.IO.StreamReader(MyMemoryStream) ){
// Extract the text from the StreamReader.
return MyReader.ReadToEnd();}
}
}