Web、デヌタベヌス、クラりド サヌビス、特泚のビゞネス管理゜フトりェアを専門ずする 20 幎以䞊の経隓を持぀倚囜籍チヌム
  • ビゞネス゜リュヌション
    • デヌタベヌスサヌビス
      • サヌバヌのアップグレヌドず DBA サヌビス
      • デヌタりェアハりス サヌビス
      • デヌタ統合
      • パワヌBI
    • りェブサむトデザむン
      • Web サむトのセキュリティ
      • Web サむトの最適化
      • ロゎデザむン
      • 支払いゲヌトりェむ
      • テクニカルツヌル
    • ビゞネスサヌビス
      • Google クラりド サヌビス
      • アマゟン りェブ サヌビス
      • マむクロ゜フト アズヌル
    • ゜ヌシャルメディア
    • マむクロ゜フトオフィス
  • å­Šæ ¡
    • テスト環境
    • 孊習デヌタベヌス
      • 基瀎
      • SQL Serverデヌタ
      • SQLServerのメンテナンス
      • SQL Serverの日付の䜿甚
      • SQLServerピボットの䜿甚-ピボット解陀
      • SQLServer関数の䜿甚
      • オヌプンク゚リを取埗
      • ツヌル
    • りェブデザむンを孊ぶ
      • Ousia コンテンツ管理システムの構築
      • ASP-NET の䜿甚
      • CSS の䜿甚
      • JavaScript の䜿甚
    • クラりドず IT サヌビスの孊習
      • タスク スケゞュヌラ ゚ラヌ 2147943645
      • OpenSSL での SSL の芁求ず PFX ファむルの生成の簡単な手順
    • ゜ヌシャル メディアの䜿甚
      • Facebookアカりントを個人甚からビゞネス甚に倉曎する
      • Google レビュヌを䟝頌する
      • ゜ヌシャル メディアの取り組みをどこに集䞭させるかを遞択する
      • ゜ヌシャル メディアの画像サむズ
      • メタ デヌタを䜿甚しお゜ヌシャル メディア画像を蚭定する
  • 私たちに関しおは
    • ブログ
      • Google コア アップデヌト 2020 幎 1 月
      • むンタヌネット䞊のりェブサむトに関する最も厄介なこず
      • りェブサむトの広告リヌフレットのコンテンツを遞択する方法
      • ゚ントリヌレベルのゲヌム機の構築
      • オンラむン詐欺の防止
      • ギグ゚コノミヌのスキマヌ
      • ホットチリむンタヌネット閉鎖
      • 無料のベクタヌ グラフィックスのトップ 5 Web サむト
    • キャリア
      • 翻蚳者 英日
      • 英語-トルコ語翻蚳者
    • チヌム
      • アむセ・ハヌ
      • アリ アル アミン
      • ギャビン・クレむトン
      • サむガングヌ
      • スヌリダ・ムッカマラ
      • スニヌル・クマヌル
      • チェスタヌコッパヌポット
    • ポヌトフォリオ
čeÅ¡tina (CS)Deutsch (DE)English (EN-GB)English (EN-US)Español (ES)Français (FR)à€¹à€¿à€‚à€Šà¥€ (HI)italiano (IT)日本語 (JA)polski (PL)Português (PT)русскОй (RU)TÃŒrk (TR)䞭囜的 (ZH)

デヌタベヌスから Web サむトの RSS フィヌドを䜜成する

チュヌトリアル: SQL Server デヌタベヌスから VB.NET たたは C#.NET を䜿甚しお、ASP.NET で Web サむト甚の倚蚀語 RSS フィヌドを䜜成する

Claytabaseによるりェブサむトのデザむン

このりォヌクスルヌを実行するには、 テスト環境の蚭定に関するガむドに埓うか、ニヌズに合わせおコヌドを調敎しおください。

経隓レベル - 侭箚

箄

RSS アむコン

RSS は、サむトに加えられた曎新に関する情報を提䟛する暙準化された XML ベヌスのファむルです。

これらは、倖出しおナヌザヌのさたざたなお気に入りのサむトの倉曎をチェックし、䜕か新しいこずを通知するさたざたなニュヌス集玄アプリケヌションで䜿甚できたす。

Web の開発の性質䞊、わずかに異なる圢匏がいく぀かありたす。以䞋の圢匏は Atom 2.0 のものです。

Sample RSS File

<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">  <channel>    <atom:link href="https://ja.claytabase.com/" rel="self" type="application/rss+xml"/>    <title/>    <link/>    <copyright>Copyright Claytabase 2012</copyright>    <language/>    <description/>    <item>      <title>Create an RSS Feed for your Website In ASP NET and SQL Server</title>      <description>Easy way to create an RSS Feed for your Website in ASP.NET in VB.NET or C#.NET</description>      <link>https://www.claytabase.co.uk/Academy/Learning-Web-Design/Using-ASP-NET/Create-an-RSS-Feed-for-your-Website-In-ASP-NET-and-SQL-Server</link>      <pubDate>Wed, 15 Dec 2021 09:37:24 GMT</pubDate>      <category>monthly</category>      <guid>https://www.claytabase.co.uk/A7038527-90D0-4214-8C65-3A2BD831F141</guid>    </item>    <item>      <title>CSS Styling for AJAX Accordion Control</title>      <description>Some simple CSS styling rules for an AJAX Accordion Control</description>      <link>https://www.claytabase.co.uk/Academy/Learning-Web-Design/Using-CSS/CSS-Styling-for-AJAX-Accordion-Control</link>      <pubDate>Tue, 14 Dec 2021 07:00:00 GMT</pubDate>      <category>monthly</category>      <guid>https://www.claytabase.co.uk/0DB19797-5B3A-45F0-B3E6-2A8080DA60EE</guid>    </item>  </channel></rss>
We've created a sample table, and run this through in our Academy Database. This table will include a UNIQUEIDENTIFIER (GUID), Title, Description, URL, language and date, this data would be the sort of information captured or required in most CMS's.
USE ClaytabaseAcademyGOCREATE TABLE RSSPages(PageGUID UNIQUEIDENTIFIER CONSTRAINT DF_PageGUID DEFAULT NEWSEQUENTIALID() CONSTRAINT PK_PageGUID PRIMARY KEY,PageTitle NVARCHAR(200),PageDescription NVARCHAR(500),PageURL NVARCHAR(500),PageLanguage NVARCHAR(2),PageDate DATETIME,ChangeFrequency NVARCHAR(20))GOINSERT INTO RSSPages(PageTitle,PageDescription,PageURL,PageDate,PageLanguage,ChangeFrequency)SELECT 'Create an RSS Feed for your Website from a database','Walkthrough: Creating an RSS Feed for your Website in ASP.NET using VB.NET or C#.NET from an SQL Server database','https://www.claytabase.co.uk/Academy/Learning-Web-Design/Using-ASP-NET/Create-an-RSS-Feed-for-your-Website-In-ASP-NET-and-SQL-Server','2021-12-15 10:00:00','en','Weekly'INSERT INTO RSSPages(PageTitle,PageDescription,PageURL,PageDate,PageLanguage,ChangeFrequency)SELECT 'CSS Styling for AJAX Accordion Control','Some simple CSS styling rules for an AJAX Accordion Control','https://www.claytabase.co.uk/Academy/Learning-Web-Design/Using-CSS/CSS-Styling-for-AJAX-Accordion-Control',GETDATE(),'en','Monthly'INSERT INTO RSSPages(PageTitle,PageDescription,PageURL,PageDate,PageLanguage,ChangeFrequency)SELECT 'We''ll take the strain while you do what you are good at','A Multi-National team with over 20 years of experience specialising in Web, Database, Cloud services and bespoke Business Management Software','https://www.claytabase.co.uk/',GETDATE(),'en','Daily'INSERT INTO RSSPages(PageTitle,PageDescription,PageURL,PageDate,PageLanguage,ChangeFrequency)SELECT 'Wir nehmen Ihnen die Anstrengung, wÀhrend Sie das tun, was Sie gut können','Ein multinationales Team mit ÃŒber 20 Jahren Erfahrung, das sich auf Web-, Datenbank-, Cloud-Dienste und maßgeschneiderte Business-Management-Software spezialisiert hat','https://de.claytabase.com/',GETDATE(),'de','Daily'INSERT INTO RSSPages(PageTitle,PageDescription,PageURL,PageDate,PageLanguage,ChangeFrequency)SELECT 'Nos esforzaremos mientras haces lo que se te da bien','Un equipo multinacional con más de 20 años de experiencia especializado en Web, bases de datos, servicios en la nube y software de gestión empresarial a medida.','https://de.claytabase.com/',GETDATE(),'es','Daily'GOCREATE PROC GetRSSPages(@Language NVARCHAR(2)) AS BEGINSELECT * FROM RSSPagesWHERE PageLanguage=@LanguageENDGOEXEC GetRSSPages 'de'

Visual Studio で新しい Web フォヌムを远加する

VS で、Pages フォルダヌを右クリックし、[远加]、[Web フォヌム] の順に遞択しお、Web フォヌムを远加したす。

コヌド ビハむンドに進みたいので、新しいペヌゞを右クリックしお [コヌドの衚瀺] を遞択したす。

コヌドはおそらく実際よりもはるかに耇雑に芋えるので、その機胜を芋おみたしょう。

たず、SQL ず XML の名前空間をむンポヌトしたす。

次に、デヌタベヌスぞの接続が蚭定されたす。これは、このむンスタンスの Web 構成から取埗されたす。

LoaderVBC#

VB

Imports System.Data.SqlClientImports System.XmlPublic Class RSS    Inherits System.Web.UI.Page    Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("SqlConnection").ConnectionString)    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load        Dim RSSLanguage As String = "en"        Dim BaseURL As String = "https://www.claytabase.co.uk/"        Dim MyTitle As String = "Academy Title"        Dim MyDescr As String = "Academy Description"
        'Clear any previous output from the buffer        Response.ClearContent()        Response.ContentType = "text/xml"        Response.Charset = "Utf-8"        Dim xtwFeed As XmlTextWriter = New XmlTextWriter(Response.OutputStream, Encoding.UTF8)        xtwFeed.WriteStartDocument()        'The mandatory rss tag        xtwFeed.WriteStartElement("rss")        xtwFeed.WriteAttributeString("version", "2.0")        xtwFeed.WriteAttributeString("xmlns:atom", "https://www.w3.org/2005/Atom")        'The channel tag contains RSS feed details        xtwFeed.WriteStartElement("channel")        xtwFeed.WriteRaw("<atom:link href="https://ja.claytabase.com/"" & BaseURL & RSSLanguage & "/rss"" rel=""self"" type=""application/rss+xml"" />")        xtwFeed.WriteElementString("title", MyTitle)        xtwFeed.WriteElementString("link", BaseURL)        xtwFeed.WriteElementString("copyright", "Copyright Claytabase 2012")        xtwFeed.WriteElementString("language", RSSLanguage)        xtwFeed.WriteElementString("description", MyDescr)
        'Objects needed for connecting to the SQL         Using com As New SqlCommand("EXEC GetRSSPages '" + RSSLanguage + "'", con)            If con.State = ConnectionState.Closed Then                con.Open()            Else            End If            Using dr = com.ExecuteReader()                'Loop through the content of the database and add them to the RSS feed                 While dr.Read()                    xtwFeed.WriteStartElement("item")                    xtwFeed.WriteElementString("title", dr.Item("PageTitle").ToString())                    xtwFeed.WriteElementString("description", dr.Item("PageDescription").ToString())                    xtwFeed.WriteElementString("link", dr.Item("PageURL").ToString())                    xtwFeed.WriteElementString("pubDate", Format(dr.Item("PageDate"), "ddd, dd MMM yyyy hh:mm:ss") + " GMT")                    xtwFeed.WriteElementString("category", dr.Item("ChangeFrequency").ToString())                    xtwFeed.WriteElementString("guid", BaseURL + "/" + dr.Item("PageGUID").ToString())                    xtwFeed.WriteEndElement()                End While            End Using        End Using        'Close all tags         xtwFeed.WriteEndElement()        xtwFeed.WriteEndElement()        xtwFeed.WriteEndDocument()        xtwFeed.Flush()        xtwFeed.Close()        Response.End()    End SubEnd Class

C#

using System.Text;using Microsoft.VisualBasic;using System.Data.SqlClient;using System.Xml;public class RSS : System.Web.UI.Page{    private SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings("SqlConnection").ConnectionString);    protected void Page_Load(object sender, System.EventArgs e)    {        string RSSLanguage = "en";        string BaseURL = "https://www.claytabase.co.uk/";        string MyTitle = "Academy Title";        string MyDescr = "Academy Description";
        // Clear any previous output from the buffer        System.Web.UI.Page.Response.ClearContent();        System.Web.UI.Page.Response.ContentType = "text/xml";        System.Web.UI.Page.Response.Charset = "Utf-8";        XmlTextWriter xtwFeed = new XmlTextWriter(System.Web.UI.Page.Response.OutputStream, Encoding.UTF8);        xtwFeed.WriteStartDocument();        // The mandatory rss tag        xtwFeed.WriteStartElement("rss");        xtwFeed.WriteAttributeString("version", "2.0");        xtwFeed.WriteAttributeString("xmlns:atom", "https://www.w3.org/2005/Atom");        // The channel tag contains RSS feed details        xtwFeed.WriteStartElement("channel");        xtwFeed.WriteRaw("<atom:link href=\"" + BaseURL + RSSLanguage + "/rss\" rel=\"self\" type=\"application/rss+xml\" />");        xtwFeed.WriteElementString("title", MyTitle);        xtwFeed.WriteElementString("link", BaseURL);        xtwFeed.WriteElementString("copyright", "Copyright Claytabase 2012");        xtwFeed.WriteElementString("language", RSSLanguage);        xtwFeed.WriteElementString("description", MyDescr);
        // Objects needed for connecting to the SQL         using (SqlCommand com = new SqlCommand("EXEC GetRSSPages '" + RSSLanguage + "'", con))        {            if (con.State == ConnectionState.Closed)                con.Open();            else            {            }            using (var dr = com.ExecuteReader())            {                // Loop through the content of the database and add them to the RSS feed                while (dr.Read())                {                    xtwFeed.WriteStartElement("item");                    xtwFeed.WriteElementString("title", dr.Item["PageTitle"].ToString());                    xtwFeed.WriteElementString("description", dr.Item["PageDescription"].ToString());                    xtwFeed.WriteElementString("link", dr.Item["PageURL"].ToString());                    xtwFeed.WriteElementString("pubDate", Strings.Format(dr.Item["PageDate"], "ddd, dd MMM yyyy hh:mm:ss") + " GMT");                    xtwFeed.WriteElementString("category", dr.Item["ChangeFrequency"].ToString());                    xtwFeed.WriteElementString("guid", BaseURL + "/" + dr.Item["PageGUID"].ToString());                    xtwFeed.WriteEndElement();                }            }        }        // Close all tags         xtwFeed.WriteEndElement();        xtwFeed.WriteEndElement();        xtwFeed.WriteEndDocument();        xtwFeed.Flush();        xtwFeed.Close();        System.Web.UI.Page.Response.End();    }}

たずめ

ペヌゞの読み蟌みからコヌドに移りたす。これは、もう少しクリ゚むティブな郚分です。

フィヌルド RSSLanguage は CMS で䜿甚され、各リク゚ストに䜿甚されおいる蚀語をシステムに䌝え、ベヌス URL も入力されたす。この䟋では、それらを静的フィヌルドにしたした。

次の数行のコヌドでは、゚ンコヌディングず応答タむプを蚭定し、XML ラむタヌを開き、必芁な芋出しをいく぀か蚭定したす。これらはめったに倉曎されないため、手動で蚭定したした。

デヌタの読み取りに移るこずができるので、最初の仕事は SQL コマンドを䜜成するこずです。この堎合、蚀語入力に応じおデヌタベヌスから必芁なフィヌルドを返すストアド プロシヌゞャを呌び出すだけです。

次に、SQL 接続を開き、デヌタベヌスからの結果セットをルヌプするデヌタ リヌダヌを宣蚀したす。

XML タグが各ドキュメントのアむテムであるこずは既にわかっおいるので、すぐに開くこずができたす。

次に、必芁な各項目にデヌタを入力し、日付が正しい圢匏であるこずを確認しおから、WriteEndElement を䜿甚しおタグを閉じたす。

デヌタがすべお読み取られるず、コヌドはデヌタ リヌダヌず接続を閉じ、以前に開いた各芁玠の終了タグを曞き蟌みたす。

䜜成しお公開したら、必ずW3C RSS Validator で確認しおください。

著者

圹に立った

Please note, this commenting system is still in final testing.

Claytabaseによるりェブサむトのデザむン

これは、圓瀟の Web サむト デザむン サヌビスの䞀郚である、垂堎で最も高速で最適化されたシステムの 1 ぀である Ousia コンテンツ管理システム コヌドから倉曎されたコヌドのセクションです。

これらは、玄£500から始たるサむトで利甚できたす.

詳现: レスポンシブで高速。コンテンツ管理システムを䜿甚した Web 開発、蚭蚈、およびホスティング
Copyright Claytabase Ltd 2020

Registered in England and Wales 08985867

RSSLoginLink お問い合わせクッキヌポリシヌサむトマップ

Social Media

facebook.com/Claytabaseinstagram.com/claytabase/twitter.com/Claytabaselinkedin.com/company/claytabase-ltd

Get in Touch

+442392064871info@claytabase.comClaytabase Ltd, Unit 3d, Rink Road Industrial Estate, PO33 2LT, United Kingdom
The settings on this site are set to allow all cookies. These can be changed on our Cookie Policy & Settings page.
By continuing to use this site you agree to the use of cookies.
Ousia Logo
Logout
Ousia CMS Loader