Get Xml Root Node - CSharp System.Xml

CSharp examples for System.Xml:XML Node

Description

Get Xml Root Node

Demo Code


using System.Xml;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//  w ww  .  j  av  a 2  s . c  o  m

public class Main{
        public static XmlNode GetXmlRootNode(String fileName, String nodeName)
        {
            XmlDocument doc = new XmlDocument();
            XmlTextReader textReader = new XmlTextReader(fileName);
            XmlNode currNode = doc.ReadNode(textReader);
            while (currNode != null)
            {
                if (currNode.NodeType == XmlNodeType.Element)
                {
                    if (currNode.Name.Equals(nodeName, StringComparison.OrdinalIgnoreCase))
                        return currNode;
                }
                currNode = doc.ReadNode(textReader);
            }
            return null;
        }
}

Related Tutorials