Get Text from XMLElement - CSharp System.Xml

CSharp examples for System.Xml:XML Element

Description

Get Text from XMLElement

Demo Code


using System.Xml;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from   www .j a v  a2s  . c om*/

public class Main{
        public static XmlText GetText(this XmlElement element)
        {
            foreach (XmlNode child in element.ChildNodes)
            {
                if (child is XmlText)
                {
                    XmlText text = (XmlText)child;
                    if (text.Data.Trim().Length > 0)
                        return text;
                }
            }
            return null;
        }
}

Related Tutorials