Ejemplo n.º 1
0
        private static int ParseAtom(Windows.Data.Xml.Dom.XmlDocument xmlDoc, ObservableCollection <FeedItem> feedItems)
        {
            int    addedItems = 0;
            string atomNS     = "xmlns:atom='http://www.w3.org/2005/Atom'";

            Windows.Data.Xml.Dom.XmlNodeList atomNodes = xmlDoc.SelectNodesNS("atom:feed/atom:entry", atomNS);

            foreach (Windows.Data.Xml.Dom.IXmlNode atomNode in atomNodes)
            {
                Windows.Data.Xml.Dom.IXmlNode atomSubNode = atomNode.SelectSingleNodeNS("atom:title", atomNS);
                string title = atomSubNode != null ? atomSubNode.InnerText : "";

                atomSubNode = atomNode.SelectSingleNodeNS("atom:link", atomNS);
                string link = atomSubNode.Attributes.Where(a => a.NodeName == "href").FirstOrDefault()?.InnerText;

                atomSubNode = atomNode.SelectSingleNodeNS("atom:summary", atomNS);
                string summary = atomSubNode != null ? atomSubNode.InnerText : "";

                feedItems.Add(new FeedItem(title, link, summary));
                addedItems++;
            }

            return(addedItems);
        }