ดาวน์โหลดโปรแกรม RSS Reader ได้ที่นี่ ...

|
|
|
Visitors - Session views |       
7 ธันวาคม พ.ศ.2549 505 Users On-Line. |
|
Visitors - Page views |        1 กุมภาพันธ์ พ.ศ.2551 |
|
|
|
 |
|
โค้ด ASP เพื่อทำการอ่านค่า RSS Feeds |
Category »
ASP/ASP.Net โดย : Webmaster เมื่อ 10/11/2549 9:02:00 | (อ่าน : 13835) |
<%@ Language=VBScript %>
<%Option Explicit%>
<%
Dim xmlDoc
Dim xmlRoot
Dim xmlPNode
Dim xmlNode
Dim strDoc
' งานนี้ต้องพึ่งพาบริการเจ้าดม (DOM) น่ะครับ
' DOM จะมองเอกสาร XML ในลักษณะของโครงสร้างต้นไม้ (Tree)
' DOM ย่อมาจาก Document Object Model โดยมีหลักการในการอ่านเอกสาร XML มาวางเป็น Tree ซึ่ง ' ในหน่วยความจำของเครื่องที่กำลังทำงาน ประกอบด้วย Element หรือ Attribute ต่างๆ ' การเข้าถึงข้อมูลจึงเป็นการเดินไปตามกิ่งก้านต่างๆ ทั้งเป็นแบบต่อเนื่องไปเรื่อยๆ หรือจะอ้างอิงกิ่งก้านเฉพาะเจาะจงลงไป หรือ Random access ก็ได้
Set xmlDoc = Server.CreateObject("Microsoft.xmldom")
xmlDoc.async = False
xmlDoc.load "http://www.g2gnet.com/News/NewsIT.xml"
Set xmlRoot = xmlDoc.documentElement
For Each xmlPNode In xmlRoot.childNodes
strDoc = strDoc & _
"<H3>" & xmlPNode.nodeName & "</H3>"
If xmlPNode.childNodes.length = 0 Then
strDoc = strDoc & _
"<I>No data</I>"
Else
strDoc = strDoc & "<table width=100% border=1 cellpadding=2 cellspacing=0 bordercolor=#000000>"
For Each xmlNode In xmlPNode.childNodes
strDoc = strDoc & "<TR>" & _
"<TD><B>" & xmlNode.nodeName & ":</B></TD>" & _
"<TD>" & xmlNode.text + "</TD>" & _
"</TR>"
Next
End If
strDoc = strDoc & "</TABLE>"
Next
Response.Write strDoc
%>
|
<%@ Language=VBScript %>
<%
strPANURL = "http://www.g2gnet.com/News/NewsIT.xml"
dim xmlDom, nodeCol, oNode, oChildNode
set xmlDom = Server.CreateObject("MSXML2.Domdocument")
xmlDOM.async = False
call xmlDom.setProperty("ServerHTTPRequest", true)
xmlDom.async = false
call xmlDom.load(strPANURL)
if not xmlDom.documentElement is nothing then
set nodeCol = xmlDom.documentElement.selectNodes("channel/item")
i = 1
Response.Write ("<table width=100% border=1 cellpadding=2 cellspacing=0 bordercolor=#000000>")
for each oNode in nodeCol
Response.Write("<tr><td>")
Response.Write("<div>" & vbCrLf)
set oChildNode = oNode.selectSingleNode("pubDate")
if not oChildNode is nothing then
strPubDate = Server.HTMLEncode(oChildNode.text)
strPubDate = replace(strPubDate, "'", "'")
strPubDate = replace(strPubDate, "&", "&")
strPubDate = replace(strPubDate, vbCrLf, "<br>")
Response.Write("<div align=left><strong>" & strPubDate & "</div></strong><br>" & vbCrLf)
end if
set oChildNode = oNode.selectSingleNode("link")
if not oChildNode is nothing then
Response.Write(" <a href='" & oChildNode.text & "' target='_blank' class='footer' style='color: #CC0000;'>")
strLink = "yes"
end if
set oChildNode = oNode.selectSingleNode("title")
if not oChildNode is nothing then
strTitle = Server.HTMLEncode(oChildNode.text)
strTitle = replace(strTitle, "'", "'")
strTitle = replace(strTitle, "&", "&")
strTitle = replace(strTitle, vbCrLf, "<br>")
Response.Write("" & strTitle & "")
end if
if strLink = "yes" then
Response.Write("</a><br><br>" & vbCrLf)
end if
set oChildNode = oNode.selectSingleNode("description")
if not oChildNode is nothing then
Response.Write("<div align=left>" & oChildNode.text & "</div><br/>" & vbCrLf & vbCrlf)
end if
i = i + 1
Response.Write("</div>" & vbCrLf)
Response.Write("</td></tr>")
next
else
Response.Write(strPANError & vbCrLf)
end if
Response.Write("</table>")
%>
|
|
|