Uz Galaxy - Info Archive top BBS   RSS
Info Archive  Info Archive開発 - 23 RSS ファイルの作成  

System.Xml.XmlTextWriter を使って、XMLファイルに出力する。

    Public Function MakeRSS(ByVal env As Environment, Optional ByVal nCatID As Integer = 0) As Boolean

        Dim writer As New System.Xml.XmlTextWriter(env.DataPath & "\rss.xml", System.Text.Encoding.UTF8)

        writer.WriteStartDocument()
        writer.WriteStartElement("rss")
        writer.WriteAttributeString("version", "2.0")
        writer.WriteStartElement("channel")
        writer.WriteElementString("title", "Uz Galaxy .NET Tips")
        writer.WriteElementString("link", "http://uz.rocket3.net/")
        writer.WriteElementString("description", "Uz Galaxy .NET Tips Update")
        writer.WriteElementString("copyright", "Copyright 2004 Uz")

        ' 新着記事20件分出力
        Dim sSql As String
        sSql = "SELECT tblInfo.InfoID, " & _
               "       tblInfo.Title, " & _
               "       tblInfo.EditDate, " & _
               "       tblCat.CatName " & _
               "  FROM tblCatInfoList, " & _
               "       tblInfo, " & _
               "       tblCat " & _
               " WHERE tblCatInfoList.InfoID = tblInfo.InfoID " & _
               "   AND tblCat.CatID = tblCatInfoList.CatID "

        If nCatID <> 0 Then
            Dim sCatList As String = GetSubCatList(nCatID)
            If sCatList.Length > 0 Then
                sSql += "   AND tblCat.CatID IN (" & sCatList & ") "
            End If
        End If

        sSql += " ORDER BY tblInfo.EditDate DESC "


        Dim db As New Database(env.MdbPath)
        Dim dr As OleDb.OleDbDataReader = db.GetReader(sSql)
        Dim nRecCnt As Integer = 0
        While dr.Read() And nRecCnt <= 20

            writer.WriteStartElement("item")
            writer.WriteElementString("title", dr.Item(1))
            writer.WriteElementString("subject", dr.Item(3))
            writer.WriteElementString("link", env.Ftp.URL & IIf(env.Ftp.URL.Substring(env.Ftp.URL.Length - 1, 1) = "/", "", "/") & "Info-" & Format(dr.Item(0), "00000") & "/index.html")
            writer.WriteElementString("description", "")
            writer.WriteElementString("pubDate", CType(dr.Item(2), Date).ToString())
            writer.WriteEndElement()

            nRecCnt += 1
        End While
        dr.Close()
        db.Dispose()

        writer.WriteEndElement()   ' channel
        writer.WriteEndElement()   ' rss
        writer.WriteEndDocument()

        writer.Flush()
        writer.Close()
    End Function


Copyright © 2004 Uz. All rights reserved.
http://uzgalaxy.com/
このページはInfoArchiveで作成されています。