Solved

ASP Classic parse of a RSS news feed not working

Posted on 2009-06-29
6
407 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

696 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