I'm working with an xml fragment, and finding that I'm doing the following a lot:
dim x = xe.Element("foo").Element("bar").Element("Hello").Element("World").Value
however I can't always guarantee that the xml document will contain foo or bar. Is there a nicer way to do this sort of thing without having to null check every query?
i.e.
dim x = ""
if xe.Element("foo").Any() then
if xe.Element("foo").Element("bar").Any() Then
if xe.Element("foo").Element("bar").Element("Hello").Any() Then
x = xe.Element("foo").Element("bar").Element("Hello").Element("World").ValueOrDefault()
End If
End If
End If
(ValueOrDefault is an extension method I've added)