CSharp examples for System.Xml:XML Attribute
Gets XML attribute or returns a default value
using System.Xml; using System.Text; using System.Collections.Generic; using System;/* w w w. j a va 2 s. c om*/ public class Main{ /// <summary> /// Gets the attribute or returns a default value /// </summary> /// <param name="xNode"></param> /// <param name="attributeName"></param> /// <param name="defaultValue"></param> /// <returns></returns> public static string RequiredParseXmlAttribute(XmlNode xNode, string attributeName) { var attr = xNode.Attributes[attributeName]; if ((attr == null) || (string.IsNullOrWhiteSpace(attr.Value))) { throw new Exception("No xml attribute found for " + attributeName); } return attr.Value; } }