ASP RSS 만들기
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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
Author: jklee@lenscloth.io
Link: https://lenscloth-ko.github.io.git/2007/11/09/ASP-RSS-만들기/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.