Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display RSS Feed 2

Status
Not open for further replies.

apex82

Programmer
Mar 2, 2009
127
0
0
GB
I want to be able to display the first 3 offers from an rss feed.

For example, something similar to this one:


I don’t want to use an external site or link to display the 3 offers, does anyone know of any examples for this?

My pages use classic ASP.

I have searched Google for an answer to this but don’t seem to be able to find an example, they all seem to use external links.

Any help would be fantastic!
 
how are you currently displaying the feed? I.e. can you show the code that outputs the current feed?

Once posted, I (or someone else) should be able to show you modifications on how to limit it to 3 items...

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
I am actually not currently showing the feed, although when I do manage to display the feed I only want to show the top 3 items.

I'm trying to find an example that would allow me to do this.

All I can find is sites that provide the service for a user rather than an example or code to display a feed.

Thanks.
 
Where is the information stored? In a db I presume...

You can create your own feed by simply querying the db for the latest three items and build an xml string with it and output it as an XML feed.

The feed does not have to have an ".xml" extention, it can be ".asp", you just need to make sure it's well formed and include the appropriate headers to output it as xml data.





--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
Firstly I hope I have understood your reply correctly..

I don't want to create my own feed and then limit that to the top 3.

I want to display the latest three items from another feed.

For example I'd like to display the top 3 from a feed similar to this one:

 
Sorry, I thought you wanted to create your own feed...

Do you have anything written to grab the entire feed from the other site? There are lots of samples online, just Google "ASP RSS Reader"

Once you have that done, you can add a counter to it to grab "x" number of "items".

If you still have problems, get the first part working and I'll help with the rest

The first part should be straight forward, sorry I'm not going to do your research for you.

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
I've spent a couple of hours searching for a classic asp example that will read an existing feed rather than an local xml file, but I can't seem to find anything.

Can anyone help? I'm really desperate!
 

About 3 links down - "stackoverflow"

If that doesn't work, try one of the other hundreds of links.


--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
Thanks Vicvirk.

I've looked at that link as well as all the other ones I think are relevant.

The "stackoverflow" link gives the following code:

Code:
<%

Dim URL, objXML, value
URL = "[URL unfurl="true"]http://someserver.com/xml"[/URL]
Set objXML = Server.CreateObject("MSXML2.DOMDocument.6.0")
objXML.setProperty "ServerHTTPRequest", True
objXML.async =  False
objXML.Load URL

Response.Write objXML.parseError.reason

value = objXML.documentElement.Text

set objXML = nothing

%>

<%= value %>

I can't fathom how I can tailor this to read a link something like this one:
Should this be relatively easy?

Thanks.
 
try replacing

Code:
URL = "[URL unfurl="true"]http://someserver.com/xml"[/URL]

with

Code:
URL = "[URL unfurl="true"]http://www.offers.co.uk/rss/food-drink"[/URL]

and see what happens

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
I had tried that but must have had a typo in there or something!

Thank you.

Is it easy to modify this to limit the output to 3 items?
 
Actually quite simple.
something like this should do:
Code:
For i = 0 to 2
 set itm = xml.getElementsByTagName("item")(i)
 response.write itm.getElementsByTagName("title")(0).Text
...
Next i

Just check the XML source code of that page and you'll easily identify the nodes title, url, description, pubDate and guid.

Just parse them similar to this example and Bob should be your uncle.
:)

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Great, thanks!

I've added the nodes, I'm getting an end of statement expected error:

Can you see where I'm going wrong?

Code:
<%

Dim URL, objXML, value 
URL = "[URL unfurl="true"]http://www.offers.co.uk/rss/food-drink"[/URL]
Set objXML = Server.CreateObject("MSXML2.DOMDocument.6.0")
objXML.setProperty "ServerHTTPRequest", True
objXML.async =  False
objXML.Load URL

Response.Write objXML.parseError.reason

value = objXML.documentElement.Text

set objXML = nothing

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>

    <%
For i = 0 to 2
 set itm = xml.getElementsByTagName("item")(i)
 Response.Write itm.getElementsByTagName("title")(0).Text
 Response.Write itm.getElementsByTagName("link")(0).Text
 Response.Write itm.getElementsByTagName("description")(0).Text
 Response.Write itm.getElementsByTagName("pubDate")(0).Text
 Response.Write itm.getElementsByTagName("guid")(0).Text

Next i

%>
</body>
</html>
 
you don't need the "i" beside "Next i"

in VBSCRIPT, the for/next loop is as follows

Code:
for i = 0 to 2
...do something
next

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
Thanks, when I remove the i after the Next I get the following error:

Code:
Microsoft VBScript runtime  error '800a01a8'

Object required: ''

/about/drss.asp, line 29

Which of course relates to this line:

Code:
set itm = xml.getElementsByTagName("item")(i)

Am I missing something simple?
 
Sorry for the "i", I forgot to remove that from the original VB6 code.

you have
Code:
value = objXML.documentElement.Text

set objXML = nothing
Which means that you assign the page contents to a String variable and then destroy the object variable.

With my code however you parse the object, not a string variable.
Leave away these two lines and replace
Code:
xml.[whatever]
with
Code:
objXML.[whatever]

Sorry for not being clearer.


[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Am I missing something simple?

You don't have an object named "xml". Your xml object is called objXML when you are creating it, but you are trying to reference it using "xml"

Also, look closley at your code and what you are doing - don't simply cut/paste example code into your script and expect it to work.

1. open the xml connection
2. get the xml response
3. parse the xml response
4. close the xml connection

What you are doing is

1. open the xml connection
2. get the xml response
4. close the xml connection
3. parse the xml reponse


If there is no connection there is nothing to parse.





--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
Thanks VicVirk and MakeItSo,

I made the changes MakeItSo highlighted and this is now working.

I just need to add some line breaks and styling and this is good to go.

Thanks again!
 
Always glad to help.
Might come in handy for me too in future.
[pipe]

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top