Indents the XML string. - CSharp System.Xml

CSharp examples for System.Xml:XML String

Description

Indents the XML string.

Demo Code


using System.Xml.Linq;
using System.Text.RegularExpressions;
using System.Xml;
using System.Text;
using System.Linq;
using System.IO;//from   w  w w . j a  v  a 2  s.com
using System.Collections.Generic;
using System;

public class Main{
        /// <summary>
        /// Indents the specifide XML string.
        /// </summary>
        public static string Indent(this string xml)
        {
            var reder = new XmlTextReader(new StringReader(xml));
            var sw = new StringWriter();
            var xmlTextWriter = new XmlTextWriter(sw) {Formatting = Formatting.Indented};
            while (reder.Read())
                xmlTextWriter.WriteNode(reder, false);
            xmlTextWriter.Close();
            reder.Close();
            return sw.ToString();
        }
}

Related Tutorials