ASP 로 RSS 읽어오기.

예전 포스팅중에
ASP 로 RSS 만들기. : http://web20korea.com/22 가 있었는데 이번에는 반대인
읽어오기를 포스팅합니다.

혼자 끙끙대던차에
http://choong.tistory.com/6 포스팅을 참고해서 운좋게 ㅋㅋ 성공했습니다.

RSS가 뭐냐고 물으시는분은..;;
요기의 WIKI 링크를 참고하시면 ㅠㅠ http://startasp.net/html/rss.asp 감사 +_+

요점은뭐 RSS에서 오는 정보를 배열로 나누어서 알아서 가공..!!
이라는 간단한 원리지만, 그래도 많이 버벅되고그랬던(저만??ㅠㅠ) 부분을
위에 참고포스팅에서 사용한 변수명을 그대로 ( 제가 짠 소스가 아닙니다, 제가짠거랑 비슷하지만 깔끔하게 되어있고 또 사용시에 전혀 이상이 없었기때문에 소스의 내용을 그대로 공개합니다 원 소스의 제작은 choong 님의 것입니다. )


우선 받아들일 RSS주소로 요청을 합니다.
Dim xmlHttp
Set xmlHttp = Server.CreateObject("MSXML2.XMLHTTP.3.0")
xmlHttp.Open "Get", RSS주소(받아들일), false
xmlHttp.Send()
받아서 저장 ( 이게 요즘은 익숙하져? ㅋㅋ )

Dim RSSXML
RSSXML = xmlHttp.ResponseText
분할을 위해 DOM객채로 저장합니다 ( 안그래도 상관없는데... 이게더 좋은거 같습니다 )

Dim xmlDOM
Set xmlDOM = Server.CreateObject("MSXML2.DomDocument.3.0")
xmlDOM.async = false
xmlDOM.LoadXml(RSSXML)
요건 센스 ㅋㅋ
Set xmlHttp = Nothing

DOM으로 저장한 객체중 item 노드로 뽑아내고 생성했던 객체는 소멸합니다.
Dim RSSItems
Set RSSItems = xmlDOM.getElementsByTagName("item")
Set xmlDOM = Nothing

이 이후에 이제 배열의 갯수 - 1개로 돌려서

'items(i,0) : title
'items(i,1) : link
'items(i,2) : description
'items(i,3) : category
'items(i,4) : author
'items(i,5) : guid
'items(i,6) : comments
'items(i,7) : pubdate

등등으로 뽑아 쓰시면 되겠습니다 ㅋㅋㅋ

위의 소스를 참고해서 만들어본것이 뭐 말이 메타블로그지만
간단하게 한번 만들어봤습니다 ㅋㅋㅋ

http://startasp.net/metablog

RSS를 읽어올 수 있음으로써 활용범위는 뭐 무한대라고 볼 수 있지 않을까요?

ㅋㅋ 저도 제 홈페이지에 날씨제공하는거 한번 받아서 붙여봤는데...

앞으로 많은 이용을 할꺼 같습니다 ( 너무 늦었나요 ㅠ? ㅋㅋ )

모두 즐프하세요~







크리에이티브 커먼즈 라이센스
Creative Commons License
이 글의 관련글
  • ASP 로 RSS 만들기. (3) [태그고리:RSS]

  • * 태그고리란? 이 글에서 사용된 태그중 어떤 태그와 연결되어 있는지 알수 있는 태그.

Posted by web20korea

2008/08/21 09:25 2008/08/21 09:25

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


블로그 이미지

web20korea's

- web20korea

Site Stats

Total hits:
54159
Today:
59
Yesterday:
232