ASP 로 RSS 만들기.

요즘들어 클라이언트 측에서 RSS요구가 몇건식 생기고있는데..사실 제공하는데야 널렸지만..
그래서 한번 정리를 하고 넘어가본다~ ㅋㅋㅋ

RSS란? 등의 설명은 찾으면 널려있고 위키백과에서는 다음과같이 설명하고 있으니 혹시
이글을 보시는 분이계시다면 한번 가보시는것도 ...
http://ko.wikipedia.org/wiki/RSS

사설 없고 바로 소스로

<?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 = "이미지 세로 사이즈"


' 여기서부터 내용

' 우선 데이터를 읽어오자
objconn = "Provider=SQLOLEDB; Data Source=DB주소; Initial Catalog=DB명; User ID=아이디; Password=비밀번호;"

SQL = "select top 50 필드1, 필드2 ... "
SQL = SQL & " , 필드x, 필드y ..."
SQL = SQL & " from 테이블명 "
SQL = SQL & " where 조건 "
SQL = SQL & " order by 어쩌구 desc "
set rs = Server.CreateObject("ADODB.Recordset")
rs.Open SQL,objconn,3

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

'이 부분에서 데이터 가공 및 함수호출을 이용한 정보 가공을 하면 된다
' ex) Name = rs(1) 이런식으로 ㅋㅋㅋ

'<item> 이라는 노드를 추가
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 = "1개의 포스트(게시글)의 제목" '제목
  item.childnodes(1).text = "고유 주소" '브라우저 주소입력창에 쳤을때 바로 그 페이지가 나오게끔 하는 주소
  item.childnodes(2).text = "본문내용" '내용 필드
  item.childnodes(3).text = "등록일" '날짜 필드
  item.childnodes(4).text = "카테고리 혹은 분류할 수 있는 테그명 등..." '분류 필드

rs.movenext
loop

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

rs.close
set rs = nothing
Set xmlPars = nothing
%>



위는 실제 사용한 소스와는 DB연결 부분 그러니까...DB연결 및 RECORDSET객채의 사용부분을 제외한
일반적으로 찾으면 나오는 양식의 초반을 주석만 바꾼것이다 ㅋㅋㅋㅋ
그래도 잘~ 돌아가니까..ㅎㅎㅎ

위와같이 작성된 페이지를 브라우저에서 볼경우에는 XML코드가 생성되어진것을 확인할 수 있으며
FISH 와 같은 RSS 리더기를 이용하여 체널을 제공받을 수 있게 되어진다..


한마디로..뭐 별거 없다 ㅋㅋㅋ
크리에이티브 커먼즈 라이센스
Creative Commons License
이 글의 관련글

Posted by web20korea

2007/11/09 23:42 2007/11/09 23:42

Trackback URL : http://web20korea.com/trackback/22

Comments List

  1. ASP 2007/11/10 00:19 # M/D Reply Permalink

    FISH 공식 사이트 : http://www.3fishes.co.kr/

  2. 향기로운바람 2008/01/11 00:21 # M/D Reply Permalink

    좋은 정보 배워 갑니다.

    1. web20korea 2008/02/18 17:15 # M/D Permalink

      엇 뭘요~;; 방문 감사합니다.~

Leave a comment
[로그인][오픈아이디란?]
« Previous : 1 : ... 187 : 188 : 189 : 190 : 191 : 192 : 193 : 194 : 195 : ... 212 : Next »

블로그 이미지

web20korea's

- web20korea

Site Stats

Total hits:
53712
Today:
48
Yesterday:
192