homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

Scraping data from an RSS feed
help needed

 4:44 pm on Oct 9, 2008 (gmt 0)

hi there I have a website that calls an rss.xml to change the currency from us to canadian if they choose...I am not a programmer and have no idea how to fix....Iam providing the code below if anyone can give me some insight I would greatly appreciate it...if you need the full url for the site let me know thanks again

function to get currency exchange rate from RSS feed
function getCurrency( sCurrency )

sBasePrice = "USD"
//sBasePrice = "CAD"

Response.Charset = "UTF-8"

Dim objXML
Dim objItemList
Dim objItem
Dim nCurrency

Set objXML = Server.CreateObject( "MSXML2.FreeThreadedDOMDocument" )
objXML.async = False

objXML.setProperty "ServerHTTPRequest", True
objXML.Load( "http://currencysource.com/RSS/" & sBasePrice & ".xml" )

' set currency exchange rate to 1 CAD = 1 USD if error with RSS feed
nCurrency = 1

' no errors
If objXML.parseError.errorCode = 0 Then

Set objItemList = objXML.getElementsByTagName( "item" )
Set objXML = Nothing

'RSS Feed childNodes: 0=title, 1=link, 2=description, 3=pubdate
For Each objItem In objItemList

' check if current item is USD
' 1 CAD = USD (0.861966)
if Mid( objItem.childNodes( 0 ).text, 1, 11 ) = "1 " & sBasePrice & " = " & sCurrency then
nCurrency = Left( Mid( objItem.childNodes( 0 ).text, 14 ), Len( Mid( objItem.childNodes( 0 ).text, 14 ) ) - 1 )
exit for
end if


Set objItemList = Nothing

End If

getCurrency = nCurrency

end function



 4:58 pm on Oct 9, 2008 (gmt 0)

What are you trying to fix?


 5:01 pm on Oct 9, 2008 (gmt 0)

when i choose canadian on the site it does not change the price just stays the same as it displayed in US funds


 8:11 pm on Oct 9, 2008 (gmt 0)

for the benefit of the group
river_east is scraping data out of an XML node that looks like this:
<title>1 USD = CAD (1.124512)</title>

* * *

so. what is returned from getCurrency("CAD") ?

I don't see anything glaringly wrong with the function. Nothing obvious anyways.

debugging tip: inject little debugging one-liner commands into your script and echo out variables to see what their values are.

for instance, echo out "objItem.childNodes( 0 ).text" and see if it is what you expect.
Then echo out "Mid( objItem.childNodes( 0 ).text, 1, 11 )". Take the code in little chunks and verify that it's doing everything right from top to bottom.

It may be something as simple as a bad boundary limit in the Mid() or Left() string functions.

Also, you may consider using a regular expression to extract the data instead of awkwardly nested substring functions.


 2:08 pm on Oct 10, 2008 (gmt 0)

it appears to be an issue with [currencysource.com...] they must have changed the path Im not sure the new path?


 5:01 pm on Oct 10, 2008 (gmt 0)

That URL gives "Directory Listing Denied" message... which leads me to beleive it hasn't move but now requires some sort of auth. It could be it limits people by referrer or IP I would contact them and inquire.


 6:18 pm on Oct 10, 2008 (gmt 0)

these two lines say it all:

sBasePrice = "USD"
objXML.Load( "http://currencysource.com/RSS/" & sBasePrice & ".xml" )

thus the URL being requested is actually

really I think the problem is something subtle in the way the data is being parsed. Or maybe it's a syntax error somewhere? I don't have the right machinery running to try your code sample out myself, and I'm very rusty on my VBScript syntax.

Debugging is a tough job, and it's a skill that takes practice. Start by "tracing [en.wikipedia.org]" values to see what they are during the execution of the code. Fixing this function should take a few minutes, not several days.

Tracing is probably the most important debugging technique you must learn, and it's much simpler than, say, bug discovery by systematic amputation, or dissecting the call stack.

The key here is to learn some debugging techniques so you can find out what the problem is. I'm guessing that once you figure out the problem, the solution will be immediately obvious.


 6:34 pm on Oct 10, 2008 (gmt 0)

great thanks for all your insight I really appriciate it...i do some testing or at least try and I'll let you know

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved