Enumerate XML Elements - CSharp System.Xml

CSharp examples for System.Xml:XML Element

Description

Enumerate XML Elements

Demo Code


using System.Xml;
using System.Text;
using System.Collections.Generic;
using System;//from www  . java2s.com

public class Main{
        public static IEnumerable<XmlElement> EnumerateElements(XmlElement source, string childName)
        {
            foreach (XmlNode child in source.ChildNodes)
            {
                if (child.NodeType == XmlNodeType.Element && childName.Equals(child.LocalName, StringComparison.OrdinalIgnoreCase))
                    yield return (XmlElement)child;
            }
        }
}

Related Tutorials