Select Single XML Attribute Date Time - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Select Single XML Attribute Date Time

Demo Code


using System.Xml;
using System;//from w w  w . j a va  2  s.  co  m

public class Main{
        public static DateTime? SelectSingleAttributeDateTime(XmlNode node, string name, DateTime? defaultValue = null)
    {
        if (node?.Attributes == null)
        {
            return defaultValue;
        }

        workAttr = node.Attributes[name];
        if (workAttr != null && DateTime.TryParse(workAttr.Value, out dtTryParse))
        {
            return dtTryParse;
        }

        return defaultValue;
    }
}

Related Tutorials