Пример #1
0
 /// <summary>link elements -> normal structure on FeedItem</summary>
 private static void normalizeFeedItemLink(FeedItem feedItem, Link link)
 {
     switch (link.rel)
     {
         case "related": break;
         case "via":
             Source source = new Source();
             source.Uri = link.href;
             source.Title = link.title;
             feedItem.Source = source;
             break;
         case "enclosure":
             int length = 0;
             Enclosure enclosure = new Enclosure();
             enclosure.Uri = link.href;
             enclosure.Title = link.title;
             enclosure.Type = link.type;
             if (Int32.TryParse(link.length, out length))
                 enclosure.Length = length;
             feedItem.Enclosures.Add(enclosure);
             break;
         case "self": break; // No link on itself (?)
         case "":
         case "alternate":
             feedItem.WebUris.Add(new FeedUri(link.href, link.title));
             break;
     }
 }
Пример #2
0
        private void readItem(XmlReader subReader)
        {
            subReader.MoveToContent();
            m_CurrentFeedItem = new FeedItem();

            while (subReader.Read())
            {
                if (subReader.NodeType == XmlNodeType.Element)
                {
                      m_CurrentNode = subReader.Name;
                      switch (m_CurrentNode)
                        {
                            case "title":
                                subReader.MoveToContent();
                                m_CurrentFeedItem.Title = subReader.ReadString();
                                break;
                            case "description":
                                subReader.MoveToContent();
                                try
                                {
                                    // One feed had a hex character / & that couldnt be read with XmlReader.
                                  m_CurrentFeedItem.Content = subReader.ReadString();
                                }
                                catch(Exception ex)
                                {
                                  System.Diagnostics.Debug.WriteLine("Error reading the description of a feed item.  Ignored usually: "+ex.Message);
                                }
                                break;
                            case "link":
                                subReader.MoveToContent();
                                FeedUri uri = new FeedUri(subReader.ReadString());
                                m_CurrentFeedItem.WebUris.Add(uri);
                                break;
                            case "author":
                                subReader.MoveToContent();
                                m_CurrentFeedItem.Authors.Add(readPerson(subReader.ReadString()));
                                break;
                            case "category":
                                Category category = new Category();
                                while (subReader.MoveToNextAttribute())
                                {
                                    if (subReader.Name == "domain")
                                        category.Scheme = subReader.Value;
                                }
                                subReader.MoveToContent();
                                category.Label = category.Term = subReader.ReadString();
                                m_CurrentFeedItem.Categories.Add(category);
                                break;
                            case "comments":
                                subReader.MoveToContent();
                                m_CurrentFeedItem.CommentsUri = subReader.ReadString();
                                break;
                            case "enclosure":
                                Enclosure enclosure = new Enclosure();
                                while (subReader.MoveToNextAttribute())
                                {
                                    switch (subReader.Name)
                                    {
                                        case "url": enclosure.Uri = subReader.Value; break;
                                        case "length":
                                            int length = 0;
                                            if (Int32.TryParse(subReader.Value, out length))
                                                enclosure.Length = length;
                                            break;
                                        case "type": enclosure.Type = subReader.Value; break;
                                    }
                                }
                                m_CurrentFeedItem.Enclosures.Add(enclosure);
                                break;
                            case "guid":
                                FeedGuid guid = new FeedGuid();
                                if (subReader.MoveToFirstAttribute())
                                {
                                    if (subReader.Name == "isPermaLink" && subReader.Value == "false")
                                        guid.PermaLink = false;
                                }
                                subReader.MoveToContent();
                                guid.Id = subReader.ReadString();
                                m_CurrentFeedItem.Guid = guid;
                                break;
                            case "pubDate":
                                subReader.MoveToContent();
                                m_CurrentFeedItem.Published = DTHelper.ParseDateTime(subReader.ReadString());
                                break;
                            case "source":
                                Source source = new Source();
                                if (subReader.MoveToFirstAttribute())
                                {
                                    if (subReader.Name == "url")
                                        source.Uri = subReader.Value;
                                }
                                subReader.MoveToContent();
                                source.Title = subReader.ReadString();
                                m_CurrentFeedItem.Source = source;
                                break;
                            default:
                                if (readModules && subReader.Prefix != String.Empty)
                                  readModuleItem(subReader, m_CurrentFeedItem);
                                break;
                        }

                    }
            }

            Feed.Items.Add(m_CurrentFeedItem);
        }