LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
No, even more then few minutes of wait doesn't help. First put url statement finishes loading, then I parse next url from downloaded html code. I have correct parsed url before second put url statement. I used "static" urls as text in put url statements to check why is this error, and to send short code making problem only.
put url "http://www.nbp.pl/home.aspx?f=/kursy/kursyc.html" into msg
put url "http://www.nbp.pl/kursy/xml/c027z140210.xml" into msg
put url "http://www.nbp.pl/kursy/xml/c027z140210.xml" into msg
on mouseUp
put "http://www.nbp.pl/home.aspx?f=/kursy/kursyc.html" & cr & "http://www.nbp.pl/kursy/xml/c027z140210.xml" into tURLList
repeat with i = 1 to the number of lines of tURLLIst
put getURL (line i of tURLList) into tRes
if tRes <> "" then
put tRes -- tried 10 times and could not get URL
exit mouseUp
end if
end repeat
end mouseUp
function getURL pURL
repeat 10 -- try 10 times, if success before return "" to stop repeat
put url pURL into msg
if the result is "" then
return ""
end if
end repeat
return "error in getting URL" && pURL
end getURL
Or something similar. This works for me.
That way you don't get stuck if it fails to work
I don't know second url until I parse it from html from first url. The name of xml file i must download is changing minimum once a day. I'm worry only if put second url twice always will be enough. So basing on your help I have idea to check if will work:
on mouseUp
local tHtml, tUrl, tXml, tNode
put url "http://www.nbp.pl/home.aspx?f=/kursy/kursyc.html" into tHtml
get matchText (tHtml, "(/kursy/xml/[a-zA-Z0-9]+\.xml)" , tUrl)
put "http://www.nbp.pl" & tUrl into tUrl
repeat with i=1 to 10
put url tUrl into tHtml
if tHtml is not empty then exit repeat
end repeat
put revXMLCreateTree (tHtml, false, true, false) into tXml
put revXMLRootNode (tXml) into tNode
put revXMLTree (tXml, tNode, return, space, true, -1) into fld "xml"
revXMLDeleteAllTrees
end mouseUp
on mouseUp
local tHtml, tUrl, tXml, tNode
put url "http://www.nbp.pl/home.aspx?f=/kursy/kursyc.html" into tHtml
get matchText (tHtml, "(/kursy/xml/[a-zA-Z0-9]+\.xml)" , tUrl)
put "http://www.nbp.pl" & tUrl into tUrl
repeat with i=1 to 10
put url tUrl into tHtml
if tHtml is not empty then exit repeat
end repeat
if tHTML is "" then -- if after 10 tries still no text then exit
answer "failure to retrieve URL"
exit mouseUp
end if
put revXMLCreateTree (tHtml, false, true, false) into tXml
put revXMLRootNode (tXml) into tNode
put revXMLTree (tXml, tNode, return, space, true, -1) into fld "xml"
revXMLDeleteAllTrees
end mouseUp
The way you had it the code would have proceeded after 10 tries even without success and the rest of your code would have failed. It is just to make shure you don't run into a problem with this hack.
And I am sure you just added RegEx to please Thierry...
Kind regards
Bernd
Yes Bernd, I didn't finnish this code yet but remember about checking all possible conditions. Actually I was working on another part of this job, but didn't want to keep you waiting for soon response. But thanks for reminder. It's fantastic to have friends who take care of quality and safety of your code.
I'm trying to learn RegEx, so I try to use it as often as possible. But of course it was for Thierry's pleasure - I knew he will want to help also