How to Load XML and Print on Console using C#

Shubham
Posted by Shubham under C# category on | Points: 40 | Views : 3605
This simple C# example will help you to load the XML doc and Print on the console using Console.WriteLine. LoadXml is used to load the XML from a string into XML Document.
============================================================================================================================================================
using System;
using System.IO;
using System.Xml;
namespace MyApp
{
class my_XML
{
static void Main(string[] args)
{
XmlDocument objDoc = new XmlDocument();
String strContent = "<Tutorial Type='CSharp_XML'><title>This is CSharp XML Example</title>" +
"</Tutorial>";
objDoc.LoadXml(strContent);

StringWriter objWriter = new StringWriter();
objDoc.Save(objWriter);
String strXML = objWriter.ToString();
Console.WriteLine(strXML);

Console.ReadLine();
}
}
}

Comments or Responses

Login to post response