简体   繁体   中英

ASP Classic reading XML Feed

I am having trouble reading the following feed. http://www.whatsonincapetown.com/feed/

my code is as follows:

<%

TheFeed = "http://www.whatsonincapetown.com/feed/"

Set xmlDOM = Server.CreateObject("MSXML2.DOMDocument")
xmlDOM.async = False
xmlDOM.setProperty "ServerHTTPRequest", True
xmlDOM.Load("TheFeed")

Set itemList = XMLDom.SelectNodes("rss[1]/channel/item") 

myCount = 0
response.write "Getting Cape Town News Feed."
For Each itemAttrib In itemList
    myCount = myCount + 1
    response.write (myCount)
    newsSubject =itemAttrib.SelectSingleNode("title").text
    newsExtract =itemAttrib.SelectSingleNode("description").text
    newsDate =itemAttrib.SelectSingleNode("pubDate").text
    %>
    <tr>
        <td><%=newsSubject%></td>
        <td><%=newsDate%></td>
        <td><%=newsExtract%></td>
    </tr>
    <%
Next

Set xmlDOM = Nothing
Set itemList = Nothing

%>

Anyone have any idea why it is not able to parse the feed, and is not giving any form of error.

Try and change

xmlDOM.Load("TheFeed")

to

xmlDOM.Load(TheFeed)

because TheFeed is a variable, not a string :-)

There's an asp script to read RSS feeds here. The comments are in Danish but that shouldn't be a problem if you understand VBS.

https://web.archive.org/web/20050517002557/http://www.html.dk/scripts/asp/00020/

However IMO the best way to parse XML with Classic ASP is to use an XSL Stylesheet. Your ASP code would look like this.

set xml = Server.CreateObject("Msxml2.DomDocument.6.0")
  xml.setProperty "ServerHTTPRequest", true
  xml.async = false
  xml.validateOnParse = false
  xml.load("http://yourfeed")
  set xsl = Server.CreateObject("Msxml2.DomDocument.6.0")
  xsl.load(Server.Mappath("yourstylesheet.xsl"))
  Response.Write(xml.transformNode(xsl))
  set xsl = nothing
  set xml = nothing

You should be able to find a ready made rss reader xsl document online somewhere

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM