Get Single XML Element Value - CSharp System.Xml

CSharp examples for System.Xml:XML Element

Description

Get Single XML Element Value

Demo Code


using System.Xml.Serialization;
using System.IO;//from   w ww.  j  ava2s.c  o m
using System.Xml;
using System.Text.RegularExpressions;
using System;

public class Main{
        public static string GetSingleElementValue(XmlDocument doc, string name, string defaultValue)
      {
         XmlElement element = GetSingleElement(doc, name);
         if (element == null)
         {
            return defaultValue;
         }
         else
         {
            return element.InnerText;
         }
      }
        public static string GetSingleElementValue(XmlDocument doc, string name)
      {
         return GetSingleElementValue(doc, name,string.Empty);
      }
}

Related Tutorials