/// <summary>
 /// Initialisiert eine neue Instanz der Atomeed Klasse.
 /// Alle Eigenschaften haben danach ihren Standartwert zugewiesen.
 /// </summary>
 public AtomFeed()
 {
     Title     = new AtomFeedText();
     SubTitle  = new AtomFeedText();
     ID        = "";
     Links     = new List <AtomFeedLink>();
     Generator = new AtomFeedGenerator();
     Logo      = "";
     Authors   = new List <AtomFeedArticlePerson>();
 }
        private void SetDocument(XDocument doc)
        {
            XNamespace ns = @"http://www.w3.org/2005/Atom";
            XElement   el = doc.Descendants(ns + "feed").Count() == 1
                    ? doc.Descendants(ns + "feed").Single()
                    : null;

            if (el == null)
            {
                throw new InvalidCastException("Invalid Atom file");
            }

            //<feed xml:lang="..." xmlns="...">...</feed>
            if (el.Attributes(XNamespace.Xml + "lang").Count() == 1)
            {
                Language = new CultureInfo(el.Attributes(XNamespace.Xml + "lang").Single().Value);
            }

            //<title>...</title>
            if (el.Elements(ns + "title").Count() == 1)
            {
                Title = new AtomFeedText()
                {
                    Text = el.Elements(ns + "title").Single().Value,
                    Type = el.Elements(ns + "title").Attributes("type").Count() == 1 ? el.Elements(ns + "title").Attributes("type").Single().Value : "",
                }
            }
            ;
            else
            {
                throw new InvalidCastException("Invalid Atom file.\title do not exists.");
            }
            //<subtitle>...</subtitle>
            if (el.Elements(ns + "subtitle").Count() == 1)
            {
                SubTitle = new AtomFeedText()
                {
                    Text = el.Elements(ns + "subtitle").Single().Value,
                    Type = el.Elements(ns + "subtitle").Attributes("type").Count() == 1 ? el.Elements(ns + "subtitle").Attributes("type").Single().Value : "",
                }
            }
            ;
            else
            {
                throw new InvalidCastException("Invalid Atom file.\nsubtitle do not exists.");
            }
            //<updated>...</updated>
            if (el.Elements(ns + "updated").Count() == 1)
            {
                Published = DateTime.Parse(el.Elements(ns + "updated").Single().Value);
            }
            //<id>MyFeed</id>
            if (el.Elements(ns + "id").Count() == 1)
            {
                ID = el.Elements(ns + "id").Single().Value;
            }
            //<link>...</link>
            Links = (from x in el.Elements(ns + "link")
                     select new AtomFeedLink()
            {
                Target = x.Attributes("href").Count() == 1 ? x.Attributes("href").Single().Value : "",
                TargetLanguage = x.Attributes("hreflang").Count() == 1 ? x.Attributes("hreflang").Single().Value : "",
                Type = x.Attributes("type").Count() == 1 ? x.Attributes("type").Single().Value : "",
                Relation = x.Attributes("rel").Count() == 1 ? x.Attributes("rel").Single().Value : "",
                Length = x.Attributes("length").Count() == 1 ? ulong.Parse(x.Attributes("length").Single().Value) : ulong.MinValue,
            }).ToList();
            //<rights>Copyright (c) 2012</rights>
            if (el.Elements(ns + "rights").Count() == 1)
            {
                Copyrights = el.Elements(ns + "rights").Single().Value;
            }
            //<generator url="..." version="...">...</generator>
            if (el.Elements(ns + "generator").Count() == 1)
            {
                Generator = new AtomFeedGenerator()
                {
                    Name    = el.Elements(ns + "generator").Single().Value,
                    Version = el.Elements(ns + "generator").Single().Attributes("version").Count() == 1 ? Version.Parse(el.Elements(ns + "generator").Single().Attributes("version").Single().Value) : new Version(0, 0, 0, 0),
                    Url     = el.Elements(ns + "generator").Single().Attributes("uri").Count() == 1 ? el.Elements(ns + "generator").Single().Attributes("uri").Single().Value : "",
                }
            }
            ;
            //<author><name>MyName</name></author>
            Authors = (from c in el.Elements(ns + "author")
                       select new AtomFeedArticlePerson()
            {
                EMail = c.Elements(ns + "email").Count() == 1 ? c.Elements(ns + "email").Single().Value : "",
                Name = c.Elements(ns + "name").Count() == 1 ? c.Elements(ns + "name").Single().Value : "",
                Uri = c.Elements(ns + "uri").Count() == 1 ? c.Elements(ns + "uri").Single().Value : "",
            }).ToList();
            //<logo>MyName</logo>
            if (el.Elements(ns + "logo").Count() == 1)
            {
                Logo = el.Elements(ns + "logo").Single().Value;
            }
            //<entry>...</entry>
            Articles = (from x in el.Elements(ns + "entry")
                        select(FeedArticleBase) new AtomFeedArticle()
            {
                Title = x.Elements(ns + "title").Count() == 1 ? x.Elements(ns + "title").Single().Value : "",
                ID = x.Elements(ns + "id").Count() == 1 ? x.Elements(ns + "id").Single().Value : "",
                Published = x.Elements(ns + "published").Count() == 1 ? DateTime.Parse(x.Elements(ns + "published").Single().Value) : DateTime.MinValue,
                Updated = x.Elements(ns + "updated").Count() == 1 ? DateTime.Parse(x.Elements(ns + "updated").Single().Value) : DateTime.MinValue,
                Authors = (from c in x.Elements(ns + "author")
                           select new AtomFeedArticlePerson()
                {
                    EMail = c.Elements(ns + "email").Count() == 1 ? c.Elements(ns + "email").Single().Value : "",
                    Name = c.Elements(ns + "name").Count() == 1 ? c.Elements(ns + "name").Single().Value : "",
                    Uri = c.Elements(ns + "uri").Count() == 1 ? c.Elements(ns + "uri").Single().Value : "",
                }).ToList(),
                Contributors = (from c in x.Elements(ns + "contributor")
                                select new AtomFeedArticlePerson()
                {
                    EMail = c.Elements(ns + "email").Count() == 1 ? c.Elements(ns + "email").Single().Value : "",
                    Name = c.Elements(ns + "name").Count() == 1 ? c.Elements(ns + "name").Single().Value : "",
                    Uri = c.Elements(ns + "uri").Count() == 1 ? c.Elements(ns + "uri").Single().Value : "",
                }).ToList(),
                Links = (from c in x.Elements(ns + "link")
                         select new AtomFeedLink()
                {
                    Target = c.Attributes("href").Count() == 1 ? c.Attributes("href").Single().Value : "",
                    TargetLanguage = c.Attributes("hreflang").Count() == 1 ? c.Attributes("hreflang").Single().Value : "",
                    Type = c.Attributes("type").Count() == 1 ? c.Attributes("type").Single().Value : "",
                    Relation = c.Attributes("rel").Count() == 1 ? c.Attributes("rel").Single().Value : "",
                    Length = c.Attributes("length").Count() == 1 ? ulong.Parse(c.Attributes("length").Single().Value) : ulong.MinValue,
                }).ToList(),
                Categories = (from c in x.Elements(ns + "category")
                              select new AtomFeedCategory()
                {
                    CategoryName = c.Attributes("label").Count() == 1 ? c.Attributes("label").Single().Value : "",
                    Term = c.Attributes("term").Count() == 1 ? c.Attributes("term").Single().Value : "",
                }).ToList(),
                Content = new AtomFeedText()
                {
                    Type = x.Elements(ns + "content").Count() == 1 ? x.Elements(ns + "content").Single().Attributes("type").Count() == 1 ? x.Elements(ns + "content").Single().Attributes("type").Single().Value : "" : "",
                    Text = x.Elements(ns + "content").Count() == 1
                           //? x.Elements(ns + "content").Single().HasElements
                                            ? x.Elements(ns + "content").Single().FirstNode.NodeType == XmlNodeType.Text || x.Elements(ns + "content").Single().FirstNode.NodeType == XmlNodeType.CDATA
                                                ? x.Elements(ns + "content").Single().Value
                                                : string.Join("", x.Elements(ns + "content").Single().Nodes().Select(n => n.ToString()))
                           //    : ""
                                        : "",
                },
                Summary = new AtomFeedText()
                {
                    Type = x.Elements(ns + "summary").Count() == 1 ? x.Elements(ns + "summary").Single().Attributes("type").Count() == 1 ? x.Elements(ns + "summary").Single().Attributes("type").Single().Value : "" : "",
                    Text = x.Elements(ns + "summary").Count() == 1
                           //? x.Elements(ns + "summary").Single().HasElements
                                            ? x.Elements(ns + "summary").Single().FirstNode.NodeType == XmlNodeType.Text || x.Elements(ns + "summary").Single().FirstNode.NodeType == XmlNodeType.CDATA
                                                ? x.Elements(ns + "summary").Single().Value
                                                : string.Join("", x.Elements(ns + "summary").Single().Nodes().Select(n => n.ToString()))
                           //    : ""
                                        : "",
                },
            }).ToList();
        }