꼭 블로그가 아니더라도 XML RSS 는 이제 어느정도 대세가 되어가고 있는 듯합니다. 이제는 언론사나 커뮤니티 등에서도 RSS 가 나옵니다.. 그리고 #Reader나 Xpyder,FreeDemon 등의 RSS 구독기 또한 점차 넓게 사용되고 있습니다. 여기서는 이러한 XML RSS 를 구현하는 방법을 ASP 기반에서 XML 컴포넌트를 이용하여 구현하고자 합니다.

사실 RSS 를 구현할때 사실 단순히 텍스트 파일로 뿌려주고 ContentType 만 xml 로 선언해줘도 가능합니다. 그러나 조금은 다르게 해보고 싶다는 저의 호기심도 있고, 확장성과 향후 유지보수에 조금이라도 더 손쉽게 하기위해서 윈도우즈 2000 에 기본제공되어 있는 XML 관련 컴포넌트를 이용하여 구현해보았습니다. 물론 아래 소스는 지금 제 블로그 RSS 의 원형이 되고 있습니다.

한가지 주의 하실점은 XML 선언전에 어떠한 개행( ) 이나 문자가 들어가서는 안됩니다. PHP 에서의 쿠키과 마찬가지 입니다.

< ?xml version="1.0" encoding="EUC-KR" ? >

< %
Response.ContentType = "text/xml"
Set xmlPars = Server.CreateObject("Msxml2.DOMDocument")

' 여기서 부터 rss 정보를 담는다.
Set rss = xmlPars.CreateElement("rss")
rss.setAttribute "version", "2.0"
rss.setAttribute "xmlns:dc", "http://purl.org/dc/elements/1.1/"
rss.setAttribute "xmlns:sy", "http://purl.org/rss/1.0/modules/syndication/"
rss.setAttribute "xmlns:admin", "http://webns.net/mvcb/"
rss.setAttribute "xmlns:rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlPars.AppendChild(rss)

'< channel> 시작

Set Channel = xmlPars.CreateElement("channel")
rss.AppendChild(Channel)

'< title>정보
Set title = xmlPars.CreateElement("title")
Channel.AppendChild(title)
Channel.childnodes(0).text = "블로그 제목"

'< link>정보
Set channel_link = xmlPars.CreateElement("link")
Channel.AppendChild(channel_link)
Channel.childnodes(1).text = "블로그 주소"

'< description>정보
Set description = xmlPars.CreateElement("description")
Channel.AppendChild(description)
Channel.childnodes(2).text = "블로그 설명"

'< dc:language>정보
Set language = xmlPars.CreateElement("dc:language")
Channel.AppendChild(language)
Channel.childnodes(3).text = "ko"

'< image>정보
Set image = xmlPars.CreateElement("image")
Channel.AppendChild(image)

'이미지 정보에 들어갈 것들
set i_title = xmlPars.CreateElement("title")
set i_url = xmlPars.CreateElement("url")
set i_width = xmlPars.CreateElement("width")
set i_height = xmlPars.CreateElement("height")

image.AppendChild(i_title)
image.AppendChild(i_url)
image.AppendChild(i_width)
image.AppendChild(i_height)

image.childnodes(0).text = "이미지 제목"
image.childnodes(1).text = "이미지 경로"
image.childnodes(2).text = "이미지 가로 사이즈"
image.childnodes(3).text = "이미지 세로 사이즈"

' 여기서 부터는 포스트에 대해서 출력

' 우선 데이터를 읽어오자
SQL = "해당되는 포스트에 대한 쿼리문"
set rs = Server.CreateObject("ADODB.Recordset")
rs.Open SQL,접근문자열,adOpenForwardOnly,adLockPessimistic,adCmdText

' 여기서 부터 루프를 돌리자.
Do until rs.EOF

' 이라는 노드를 추가
Set item = xmlPars.CreateElement("item")
Channel.AppendChild(item)

' 여기서부터 해당 포스트의 세부 정보를 출력
set title = xmlPars.CreateElement("title") '
set link = xmlPars.CreateElement("link")
set description = xmlPars.CreateElement("description")
set dcdate = xmlPars.CreateElement("dc:date")
set dcsubject = xmlPars.CreateElement("dc:subject")

item.AppendChild(title)
item.AppendChild(link)
item.AppendChild(description)
item.AppendChild(dcdate)
item.AppendChild(dcsubject)

item.childnodes(0).text = rs("제목필드")
item.childnodes(1).text = rs("포스트 고유 url 필드")
item.childnodes(2).text = rs("내용 필드")
item.childnodes(3).text = rs("날짜 필드")
item.childnodes(4).text = rs("포스트의 분류 필드")

rs.movenext
oop

' 마지막으로 최종적으로 뿌려주자.
Response.Write xmlPars.xml

'마무리 ^^;

rs.close
set rs = nothing
Set xmlPars = nothing

% >
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기

Posted by 홍반장

2007/06/16 12:42 2007/06/16 12:42
Response
No Trackback , a comment
RSS :
http://tcbs17.cafe24.com/tc/rss/response/2475

Trackback URL : http://tcbs17.cafe24.com/tc/trackback/2475

« Previous : 1 : ... 3938 : 3939 : 3940 : 3941 : 3942 : 3943 : 3944 : 3945 : 3946 : ... 6391 : Next »

블로그 이미지

- 홍반장

Archives

Recent Trackbacks

Calendar

«   2024/05   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Statistics Graph

Site Stats

Total hits:
185531
Today:
534
Yesterday:
328