Gets the first XML element. - CSharp System.Xml

CSharp examples for System.Xml:XML Element

Description

Gets the first XML element.

Demo Code


using System.Xml.Serialization;
using System.IO;/* w ww . j ava  2s.c om*/
using System.Xml;
using System.Text.RegularExpressions;
using System;

public class Main{
        /// <summary>
        /// Gets the first element.   
        /// </summary>
        /// <param name="doc">The doc.</param>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        /// <remarks></remarks>
      public static XmlElement GetFirstElement(XmlDocument doc, string name)
      {
         XmlNodeList list = doc.GetElementsByTagName(name);
         if (list == null)
         {
            return null;
         }
         return (XmlElement) list.Item(0);
      }
}

Related Tutorials