Tuesday, July 9, 2013

How to Read RSS feed Using Classic ASP


Function BinaryToString(byVal Binary)
'--- Converts binary to text
'--- Set the return value in case of error
BinaryToString = ""
'--- Creates ADODB Stream data
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
'--- Specify stream type data.
BinaryStream.Type = 1 '--- adTypeBinary
'--- Open the stream And write text/string data To the object
BinaryStream.Open
BinaryStream.Write Binary
'--- Change stream type to text
BinaryStream.Position = 0
BinaryStream.Type = 2 '--- adTypeText
'--- Specify  unicode data.
BinaryStream.CharSet = "UTF-8"
'--- Return converted text
BinaryToString = BinaryStream.ReadText
End Function



Sub GetMyData
Dim MyhorosignArray : MyhorosignArray = Array ("A","B","C","D","E","F","G","H","I","J","K","L")
Dim objHTTP, strBuff, objXML, objLst, intNoOfHeadlines, objHdl
Set objHTTP = CreateObject("Microsoft.XMLHTTP")
objHTTP.Open "GET", "RSS-FEED-URL", False
objHTTP.Send
If objHTTP.Status = 200 Then strBuff = BinaryToString(objHTTP.ResponseBody)
Set objHTTP = Nothing
If Len(strBuff) > 0 Then
Set objXML = CreateObject("Microsoft.XMLDOM")
objXML.async = False
objXML.LoadXML(strBuff)
If objXML.parseError.errorCode <> 0 Then
Response.Write objXML.parseError.errorCode & " (" & objXML.parseError.reason & ")"
Else
Set objLst = objXML.getElementsByTagName("item")
intNoOfHeadlines = objLst.length -1
For i = 0 To 11 'intNoOfHeadlines
Set objHdl = objLst.item(i)
Ref = objHdl.childNodes(0).text
Link = objHdl.childNodes(1).text
Text =  objHdl.childNodes(2).text
        Response.Write Text
Set objHdl = Nothing
Next
Set objLst = Nothing
End If
Set objXML = Nothing
End If
End Sub

No comments:

Post a Comment