CSharp examples for System.Xml:XML Element
Gets the single XML element value.
using System.Xml.Serialization; using System.IO;/*from w w w . j ava 2 s.c o m*/ using System.Xml; using System.Text.RegularExpressions; using System; public class Main{ /// <summary> /// Gets the single element value. /// </summary> /// <param name="doc">The doc.</param> /// <param name="name">The name.</param> /// <param name="defaultValue">The default value.</param> /// <returns></returns> /// <remarks></remarks> public static string GetSingleElementValue(XmlDocument doc, string name, string defaultValue) { XmlElement element = GetSingleElement(doc, name); if (element == null) { return defaultValue; } else { return element.InnerText; } } /// <summary> /// Gets the single element value. /// </summary> /// <param name="doc">The doc.</param> /// <param name="name">The name.</param> /// <returns></returns> /// <remarks></remarks> public static string GetSingleElementValue(XmlDocument doc, string name) { return GetSingleElementValue(doc, name,string.Empty); } }