XElement Helpers

Some really basic and helpful safe readers for the System.Xml.Linq.XElement object.

https://gist.github.com/CGaskell/8913779

I don’t want to copy the source here as it’ll not stay updated with the gist. But the methods are as:

public static T ChildNodeValue<T>(this XElement element, string nodeName)

public static List<int> ChildNodeValueAsListOfIntegers(this XElement element, string nodeName)

public static T AttributeValue<T>(this XElement element, string attributeName)

They’ll perform a safe cast to your type and handle the existence of child nodes etc.