Exemplo n.º 1
0
        private void GetFeedData(string url)
        {
            XmlTextReader reader = new XmlTextReader(url);
            string        localName;
            bool          channelFound = false;

            while (reader.Read())
            {
                XmlNodeType nt = reader.NodeType;

                if (reader.NodeType == XmlNodeType.Element)
                {
                    // Set name
                    localName = reader.LocalName.ToLower();

                    if (!channelFound)
                    {
                        if (localName == CHANNEL_ELEMENT)
                        {
                            // Found main body of the feed
                            channelFound = true;
                        }
                    }
                    else if (localName == ITEM_ELEMENT)
                    {
                        // Read an item
                        this.Items.Add(ReadItem(reader, ITEM_ELEMENT));
                    }
                    else if (localName == IMAGE_ELEMENT)
                    {
                        // Read image
                        _imageItem = ReadItem(reader, IMAGE_ELEMENT);
                    }
                    else
                    {
                        // Move to the Text content
                        if (XmlNodeType.Element == reader.MoveToContent())
                        {
                            // Read the Text content
                            string content = reader.ReadString();

                            // Make sure there are no nested elements
                            if (XmlNodeType.EndElement == reader.NodeType)
                            {
                                // If not, then add
                                this.SetAttribute(reader.LocalName, content);
                            }
                            else
                            {
                                // Strange - a nested element - we should ignore
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void Load(string url)
        {
            // Load URL
            _url = url;

            // Reset
            _imageItem = null;
            _items     = null;

            // Load
            GetFeedData(_url);
        }
Exemplo n.º 3
0
		public void Load(string url)
		{
			// Load URL
			_url = url;

			// Reset
			_imageItem = null;
			_items = null;

			// Load
			GetFeedData(_url);
		}
Exemplo n.º 4
0
        private RssItem ReadItem(XmlTextReader reader, string name)
        {
            bool    endFound = false;
            RssItem item     = new RssItem();

            while (!endFound && reader.Read())
            {
                if ((reader.NodeType == XmlNodeType.EndElement) && (reader.LocalName.ToLower() == name))
                {
                    endFound = true;
                }
                else if (reader.NodeType == XmlNodeType.Element)
                {
                    // Get Local name
                    item.SetAttribute(reader.LocalName, reader.ReadString());
                }
            }

            // Return item
            return(item);
        }
Exemplo n.º 5
0
		private RssItem ReadItem(XmlTextReader reader, string name)
		{
			bool	endFound = false;
			RssItem item = new RssItem();

			while (!endFound && reader.Read())
			{
				if ((reader.NodeType == XmlNodeType.EndElement) && (reader.LocalName.ToLower() == name))
				{
					endFound = true;
				}
				else if (reader.NodeType == XmlNodeType.Element)
				{
					// Get Local name
					item.SetAttribute(reader.LocalName, reader.ReadString());
				}
			}

			// Return item
			return item;
		}
Exemplo n.º 6
0
		private void GetFeedData(string url)
		{
			XmlTextReader		reader = new XmlTextReader(url);
			string				localName;
			bool				channelFound=false;

			while (reader.Read())
			{
				XmlNodeType nt = reader.NodeType;

				if (reader.NodeType == XmlNodeType.Element)
				{
					// Set name
					localName = reader.LocalName.ToLower();

					if (!channelFound)
					{
						if (localName == CHANNEL_ELEMENT)
						{
							// Found main body of the feed
							channelFound = true;
						}
					}
					else if (localName == ITEM_ELEMENT)
					{
						// Read an item
						this.Items.Add(ReadItem(reader, ITEM_ELEMENT));
					}
					else if (localName == IMAGE_ELEMENT)
					{
						// Read image
						_imageItem = ReadItem(reader, IMAGE_ELEMENT);
					}
					else
					{
						// Move to the Text content
						if (XmlNodeType.Element == reader.MoveToContent())
						{
							// Read the Text content
							string	content = reader.ReadString();

							// Make sure there are no nested elements
							if (XmlNodeType.EndElement == reader.NodeType)
							{
								// If not, then add
								this.SetAttribute(reader.LocalName, content);
							}
							else
							{
								// Strange - a nested element - we should ignore
							}
						}
					}
				}
			}
		}