Get First Child from XmlNode - CSharp System.Xml

CSharp examples for System.Xml:XML Node

Description

Get First Child from XmlNode

Demo Code


using System.Xml;
using System.Text;
using System.Collections.Generic;
using System;/*  ww w .  j a v  a2 s .  c  om*/

public class Main{
        public static XmlElement GetFirstChild(XmlNode node, string tagName)
        {
            foreach (XmlNode child in node.ChildNodes)
            {
                if (child.NodeType == XmlNodeType.Element && tagName.Equals(child.LocalName, StringComparison.OrdinalIgnoreCase))
                    return (XmlElement)child;
            }
            return null;
        }
}

Related Tutorials