views:

29

answers:

0

Hi guys

I'm just starting a project which requires some pretty hardcore linq to xml to be used and I am just wondering what people consider best practice and lessons learnt.

For instance, I am worried about all the nulls that are possible all over the place... This is something that I am using but how do other people deal with it:

    public static XElement SelectOrDefault(this XElement element, XName name)
    {
        return element == null ? null : element.Element(name);
    }

    public static IEnumerable<XElement> SelectManyOrDefault(this XElement element, XName name)
    {
        return element == null ? null : element.Elements(name);
    }

Also the fact that the names of the nodes are always strings... how are people dealing with this, I was thinking maybe a static class which has the elements and attributes as properties so that I am not using strings all the time all over the place.

What patterns are people using... Like I saw this Using LINQ to XML with the Composite Pattern... is this best practice?

Any advice would be appreciated.

Cheers Anthony