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!

Store XML output of script once per day 1

Status
Not open for further replies.

Stretchwickster

Programmer
Apr 30, 2001
1,746
0
0
GB
Hi there,

I'm completely new to classic ASP, but have a fair bit of server-side experience with PHP.

I've cobbled together the following simple ASP script (called xml_echo.asp) which echoes the XML output from a PHP script (due to constraints imposed on me, I'm not permitted by my employer to directly access one of our remote databases from the ASP environment - hence this workaround):
Code:
<%
  Dim objParser
  Set objParser = Server.CreateObject("Msxml2.DomDocument")
  objParser.async = false
  objParser.setProperty "ServerHTTPRequest", true
  objParser.load("[URL unfurl="true"]http://www.mydomain.com/data.php")[/URL]
  if objParser.parseError.errorCode <> 0 then
    Response.Write(objParser.parseError.reason)
  else
    Response.ContentType = "text/xml"
    Response.Write objParser.xml
  end if
  Set objParser = nothing
%>
Since the XML output from the PHP script doesn't change often, I would ideally like to cache the output of this ASP script, so that the PHP script is only called once per day. Does anyone have any suggestions as to the best way to achieve this?

Your advice would be much appreciated.

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
May try the logic embedded in this draft.
[tt]
<%
Set objParser = Server.CreateObject("Msxml2.DomDocument")
objParser.async = false

set fso=createobject("scripting.filesystemobject")
set tfolder = fso.GetSpecialFolder(2) 'temporaryfolder=2

[blue]txmlcache="data.php.xml"[/blue] 'a given and as desired

on error resume next
set f=fso.getfile(tfolder.path & "\" & txmlcache)
if err.number=0 then
if [blue]f.datelastmodified < date-1[/blue] then 'to refine to your exact desire
err.raise 255
end if
end if

if err.number=0 then
objParser.load f.path
if objParser.parseError.errorCode <> 0 then
err.raise 254
else
response.type="text/xml"
response.write objParser.xml
end if
end if

if err.number<>0 then
objParser.setProperty "ServerHTTPRequest", true
objParser.load("[ignore][/ignore]")
if objParser.parseError.errorCode <> 0 then
Response.Write(objParser.parseError.reason)
else
'save a copy as cache
fso.createtextfile(tfolder.path & "\" & txmlcache,true,-2).write objParser.xml 'system default -2
Response.ContentType = "text/xml"
Response.Write objParser.xml
end if
end if
set f=nothing
on error goto 0
set tfolder=nothing
set fso=nothing
set objParser=nothing
%>
[/tt]
 
Wow - thanks Tsuji. I wasn't expecting a full code solution. That's exactly what I was after.

P.S. for anyone picking this code up at a later date, please ensure you include the word highlighted in red on the appropriate line:
Code:
response.[COLOR=red]content[/color]type="text/xml"

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Thanks Clive for the note on the amendment. Here is the entire block involved.
[tt]
if err.number=0 then
objParser.load f.path
if objParser.parseError.errorCode <> 0 then
err.raise 254
else
response.[red]content[/red]type="text/xml"
response.write objParser.xml
end if
end if
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top