Solved

ASP Classic parse of a RSS news feed not working

Posted on 2009-06-29
6
395 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now