Get Xml String from file - CSharp System.Xml

CSharp examples for System.Xml:XML String

Description

Get Xml String from file

Demo Code


using System.Xml;
using System.Text;
using System.Linq;
using System.IO;/*from w ww .j  a va 2  s  .c  om*/
using System.Collections.Generic;
using System;

public class Main{
        public static string GetXmlString(string strFile)
        {
            // Load the xml file into XmlDocument object.
            XmlDocument xmlDoc = new XmlDocument();
            try
            {
                xmlDoc.Load(strFile);
            }
            catch (XmlException e)
            {
                Console.WriteLine(e.Message);
            }
            // Now create StringWriter object to get data from xml document.
            StringWriter sw = new StringWriter();
            XmlTextWriter xw = new XmlTextWriter(sw);
            xmlDoc.WriteTo(xw);
            return sw.ToString();
        }
}

Related Tutorials