Solved

ASP Classic parse of a RSS news feed not working

Posted on 2009-06-29
6
392 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…
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…

705 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

22 Experts available now in Live!

Get 1:1 Help Now