top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to Convert XmlDocument to XDocument in C# ?

0 votes
358 views
How to Convert XmlDocument to XDocument in C# ?
posted Jun 9, 2016 by Sathyasree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
using System;
using System.Xml;
using System.Xml.Linq;

namespace ACCode
{
    class Program
    {
        static void Main(string[] args)
        {
            var xmlDocumentobj = new XmlDocument();
            xmlDocumentobj.LoadXml("<Root><User1>Test</User1></Root>");
            var xDocument = ConvertToXDocument(xmlDocumentobj);

            Console.ReadLine();
        }

        // Method to convert the XmlDocument to XDocument
        public static XDocument ConvertToXDocument( XmlDocument input)
        {
            using (var reader = new XmlNodeReader(input))
            {
                reader.MoveToContent();
                return XDocument.Load(reader);
            }
        }

    } 
}
answer Jun 9, 2016 by Shivaranjini
...