Convert XML Node - CSharp System.Xml

CSharp examples for System.Xml:XML Node

Description

Convert XML Node

Demo Code


using System.Xml.XPath;
using System.Xml.Serialization;
using System.Xml.Linq;
using System.Xml;
using System.Linq;
using System.IO;/*w w w.  j av  a  2  s  . c om*/
using System.Collections.Generic;

public class Main{
        public static T ConvertNode<T>(XmlNode node) where T : class
        {
            MemoryStream stm = new MemoryStream();

            StreamWriter stw = new StreamWriter(stm);
            stw.Write(node.InnerXml);
            stw.Flush();

            stm.Position = 0;

            XmlSerializer ser = new XmlSerializer(typeof(T));
            T result = (ser.Deserialize(stm) as T);

            return result;
        }
}

Related Tutorials