Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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
    {
        // Load the XmlDocument with the XML.
        document.LoadXml(xml);

        writer.Formatting = Formatting.Indented;

        // Write the XML into a formatting XmlTextWriter
        document.WriteContentTo(writer);
        writer.Flush();
        mStream.Flush();

        // Have to rewind the MemoryStream in order to read
        // its contents.
        mStream.Position = 0;

        // Read MemoryStream contents into a StreamReader.
        StreamReader sReader = new StreamReader(mStream);

        // Extract the text from the StreamReader.
        string formattedXml = sReader.ReadToEnd();

        result = formattedXml;
    }
    catch (XmlException)
    {
        // Handle the exception
    }

    mStream.Close();
    writer.Close();

    return result;
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: remove numericUpDown white space 
Csharp :: unity mathf.clamp 
Csharp :: unity android keycodes 
Csharp :: c# convert string to base64 string 
Csharp :: c# check multiple variables for null 
Csharp :: c# odp.net close session 
Csharp :: How to cache database tables to prevent many database queries in Asp.net C# mvc 
Csharp :: list findall c# 
Csharp :: linq query to fetch parent child data from same table in c# 
Csharp :: windows forms webbrowser goforward 
Csharp :: MissingMethodException: PlayerManager.OnPlayerLeft Due to: Attempted to access a missing member. 
Csharp :: how to hide tree level button when no record found for devexpress child grid view in Winform c# 
Csharp :: save and query mongodb collection as dynamic ExpandoObject 
Csharp :: how to increase alpha in strings using unity 
Csharp :: C# program to find sum of array elements 
Csharp :: index sort 
Csharp :: angular === vs == 
Csharp :: control shot c# WF 
Csharp :: back color for DateTimePicker control 
Csharp :: list to array f# 
Csharp :: text mesh pro 
Csharp :: ${1##*[! ]} 
Csharp :: ExpandoObject Convert to Json or Json to ExpandoObject 
Csharp :: inline c# custom operator implicit 
Csharp :: unrecognized escape sequence c# connection string 
Csharp :: c# move picturebox 
Csharp :: the range data annotation attribute (Double) 
Csharp :: c# get first and last day of current month 
Csharp :: invalid length for a base-64 char array or string. frombase64string c#Add Answer 
Csharp :: c sharp switch forms 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =