Solved

ASP Classic parse of a RSS news feed not working

Posted on 2009-06-29
6
401 Views
Last Modified: 2013-11-08
Thanks in advance for any help.

I have an ASP classic basic script which reads an xml file (http://gsmworld.com/rss/press_releases_2009.xml) and converts it to a JSON string.

It works fine on several feeds, apart from the above mentioned one, which gives me the error:

Microsoft VBScript runtime  error '800a01a8'

Object required: 'oDOM.documentElement'

/get/feed/Default.asp, line 21

Line 21 and it's surround code is below.

So anyone got any idea, why this XML feed would have an issue? Or, does anyone know of a good standard for parsing XML using ASP?

vConfig is just the body of the XML feed, pulled in via an http request.
Set oDOM = server.CreateObject("MSXML2.DOMDocument")
		oDOM.LoadXML(vConfig)
		
 
Line 21 >	Set oRoot = oDOM.documentElement.selectSingleNode("/rss")
			on error resume next
			nVersion 		= oRoot.selectSingleNode("@version").text
			if nVersion = "2.0" then
				vTitle			= oDOM.documentElement.selectSingleNode("/rss/channel/title").text
				vLink			= oDOM.documentElement.selectSingleNode("/rss/channel/link").text
				vDescription	= oDOM.documentElement.selectSingleNode("/rss/channel/description").text
				vLanguage		= oDOM.documentElement.selectSingleNode("/rss/channel/language").text

Open in new window

0
Comment
Question by:jhaley-telecomtv
  • 3
  • 3
6 Comments
 
LVL 3

Expert Comment

by:giuseppepi
ID: 24734921
Try out this one
<%
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.setProperty "ServerHTTPRequest", true 
 
objXML.async = False
 
'Carica il file XML o il feed rss in formato xml
strFile= "http://gsmworld.com/rss/press_releases_2009.xml"
objXML.Load (strFile)
 
Set AllItems = objXML.selectNodes("//channel")
 
For I = 0 to (AllItems.Length - 1)
  Set Post = AllItems(I).selectNodes("item")
  For J = 0 to (Post.Length-1)
      Set title = Post(J).selectNodes("title")
      Set description = Post(J).selectNodes("description")
      Set link = Post(J).selectNodes("link")
      Set lang = Post(J).selectNodes("language")
 
%>
<a href="<%=link(0).text%>" target="_blank"><%=title(0).text%></a><br>
<%=description(0).text%><br><%= language(0).text%><br><br>
<%
  Next
    Set title = Nothing
    Set description = Nothing
    Set link = Nothing
    Set Post = Nothing
Next
%>

Open in new window

0
 
LVL 3

Expert Comment

by:giuseppepi
ID: 24734964
Try out this one
<%
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.setProperty "ServerHTTPRequest", true 
 
objXML.async = False
 
'Carica il file XML o il feed rss in formato xml
strFile= "http://gsmworld.com/rss/press_releases_2009.xml"
objXML.Load (strFile)
 
Set AllItems = objXML.selectNodes("//channel")
 
For I = 0 to (AllItems.Length - 1)
  Set Post = AllItems(I).selectNodes("item")
  For J = 0 to (Post.Length-1)
      Set title = Post(J).selectNodes("title")
      Set description = Post(J).selectNodes("description")
      Set link = Post(J).selectNodes("link")
      Set language = Post(J).selectNodes("language")
 
%>
<a href="<%=link(0).text%>" target="_blank"><%=title(0).text%></a><br>
<%=description(0).text%><br><%=language(0).text%><br><br>
<%
  Next
    Set title = Nothing
    Set description = Nothing
    Set link = Nothing
    Set Post = Nothing
    Set language = Nothing
Next
%>

Open in new window

0
 

Author Comment

by:jhaley-telecomtv
ID: 24735986
That doesn't work, I get a Object Required message when trying to use that script. It's because some of the data, like description isn't available on all records!
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:jhaley-telecomtv
ID: 24736006
This is the full current code:
Dim vConfig : Dim vResponse
		vConfig = GetFile(request("f"))
		
		'prep json response
		vResponse =  "{""news"":"
		
		Set oRE= new RegExp : oRE.Pattern="[\f\n\r\t\v]| {2,}" : oRE.IgnoreCase = true : oRE.Global = true
		vConfig=oRE.Replace(vConfig,"")
		
		' Read config file
		Set oDOM = server.CreateObject("MSXML2.DOMDocument")
		oDOM.LoadXML(vConfig)
		
		' Set Root and get page properties
		Set oRoot = oDOM.documentElement.selectSingleNode("/rss")
			on error resume next
			nVersion 		= oRoot.selectSingleNode("@version").text
			if nVersion = "2.0" then
				vTitle			= oDOM.documentElement.selectSingleNode("/rss/channel/title").text
				vLink			= oDOM.documentElement.selectSingleNode("/rss/channel/link").text
				vDescription	= oDOM.documentElement.selectSingleNode("/rss/channel/description").text
				vLanguage		= oDOM.documentElement.selectSingleNode("/rss/channel/language").text
				
				'output settings
				vResponse=vResponse & "{""state"":""pass"",""title"":""" & vTitle & """,""link"":""" & vLink & """,""description"":""" & vDescription & """,""language"":""" & vLanguage & ""","
				
				'ouput items
				vResponse=vResponse & """items"":["
				
				Set oItems = oRoot.selectNodes("//item")
					if oItems.length > 0 then
						for each oItem in oItems
							vResponse=vResponse & "{""title"":""" & oItem.selectSingleNode("title").text & ""","
							vResponse=vResponse & """description"":""" & oItem.selectSingleNode("description").text & ""","
							vResponse=vResponse & """link"":""" & oItem.selectSingleNode("link").text & ""","
							vResponse=vResponse & """guid"":""" & oItem.selectSingleNode("guid").text & ""","
							vPubDate = oItem.selectSingleNode("pubDate").text
							if vPubDate = "" then
								vResponse=vResponse & """pubDate"":""""},"
							else
								vResponse=vResponse & """pubDate"":""" & vPubDate & """},"
							end if
						next
					end if
				vResponse=left(vResponse,len(vResponse)-1)
				vResponse=vResponse & "]}"
			else
				vResponse=vResponse & "{""state"":""fail""}"
			end if
		
		vResponse = vResponse & "}"
		
		' Clean up
		vResponse=replace(vResponse,"","&quot;")
		vResponse=replace(vResponse,"","&quot;")
		vResponse=replace(vResponse,"","'")
		vResponse=replace(vResponse,"®","&reg;")
		vResponse=replace(vResponse,""","&#8482;")
		
		' Output 
		response.write vResponse

Open in new window

0
 
LVL 3

Expert Comment

by:giuseppepi
ID: 24736935
Yeah, true. I did not try before!
But the error is in language! I got it working.
<%
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.setProperty "ServerHTTPRequest", true 
 
objXML.async = False
 
'Carica il file XML o il feed rss in formato xml
strFile= "http://gsmworld.com/rss/press_releases_2009.xml"
objXML.Load (strFile)
 
Set AllItems = objXML.selectNodes("//channel")
 
For I = 0 to (AllItems.Length - 1)
  Set Post = AllItems(I).selectNodes("item")
  For J = 0 to (Post.Length-1)
      Set title = Post(J).selectNodes("title")
      Set description = Post(J).selectNodes("description")
      Set link = Post(J).selectNodes("link")
 
 
%>
<a href="<%=link(0).text%>" target="_blank"><%=title(0).text%></a><br>
<%=description(0).text%><br><br>
<%
  Next
    Set title = Nothing
    Set description = Nothing
    Set link = Nothing
    Set Post = Nothing
Next
%>

Open in new window

0
 

Accepted Solution

by:
jhaley-telecomtv earned 0 total points
ID: 24737499
Thanks for the response. I found another solution, using Yahoo Pipes to generate the JSON  for me.

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question