質問

VS2010、C#他のサイトからRSSコンテンツを読み、それらを私のサイトに表示したい、現在このプロセスは手動で実行されます(サイト管理者は他のサイトを検索し、ニュースアイテムで関連コンテンツをコピー/ペーストします)。自動的にそれをやりたいと思います、私は最善の解決策がRSSであると思います、私はいくつかのサンプルコードを試しましたが、それらのどれも働いていませんでした、ASP.NETでRSSリーダーを実装する簡単な方法はありますか?ここで私のオプションは何ですか?

役に立ちましたか?

解決

RSSリンク
public void ReadDoc(XmlDocument rssDoc)
{
    XmlNode nodeRss = null;
    XmlNode nodeChannel = null;
    XmlNode nodeItem = null;
    try
    {
        if (rssDoc == null)
        {
            return;
        }

        // Loop for the <rss> tag
        for (int i = 0; i < rssDoc.ChildNodes.Count; i++)
        {
            // If it is the rss tag
            if (rssDoc.ChildNodes[i].Name == "rss")
            {
                 nodeRss = rssDoc.ChildNodes[i];
                 break;
            }
        }

        if (nodeRss == null)
        {
            return;
        }
        for (int i = 0; i < nodeRss.ChildNodes.Count; i++)
        {
            if (nodeRss.ChildNodes[i].Name == "channel")
            {
                nodeChannel = nodeRss.ChildNodes[i];
                break;
            }
        }

        if (nodeChannel == null)
        {
            return;
        }

        // Loop for the <title>, <link>, <description> and all the other tags
        for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)
        {
            if (nodeChannel.ChildNodes[i].Name == "item")
            {
                nodeItem = nodeChannel.ChildNodes[i];
                if (nodeItem["title"] != null){}
                if (nodeItem["description"] != null){}
                if (nodeItem["pubDate"] != null){}
            }
        }
    }
    catch (Exception)
    {
        throw;
    }
    finally
    {
        nodeRss = null;
        nodeChannel = null;
        nodeItem = null;
    }
}
.
public void CreateRSS(String Path)
{
    XmlDocument doc = null;
    XmlTextReader rssReader = null;
    Label doclbl = null;
    Label snolbl = null;
    try
    {
        try
        {
            rssReader = new XmlTextReader(Path);
        }
        catch (Exception)
        {
            return;
        }

        if (rssReader == null)
        {
            return;
        }

        doc = new XmlDocument();
        try
        {
            doc.Load(rssReader);
        }
        catch (Exception)
        {
            return;
        }

        if (doc == null)
        {
            return;
        }

        ReadDoc(doc);
    }
    catch (Exception)
    {
        throw;
    }
    finally
    {
        doc = null;
        rssReader = null;
        doclbl = null;
        snolbl = null;
    }
}
.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top