Adding Response.Write "nodeName = " & oXML.documentElement.nodeName & "<br>"
after oXML.load(cURL) gives me an error:
Object required: 'documentElement'
It seems like I had to add an extra step to get it to work, which I don't
like as your's is cleaner. Do you have any ideas as to why this was
necessary or any further steps in trouble shooting?
set objHTTP = Server.CreateObject("Microsoft.XMLHTTP")
objHTTP.open "GET", cURL, false
objHTTP.send
set objXML = objHTTP.responseXML
Complete code:
<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit
'*
Const cOZT = 31.103477
Const cURL = "http://dgcsc.org/goldprices.xml"
'*
Dim iPRC, objHTTP, objXML, oXML
iPRC = 0.0000
'*
set objHTTP = Server.CreateObject("Microsoft.XMLHTTP")
objHTTP.open "GET", cURL, false
objHTTP.send
set objXML = objHTTP.responseXML
set oXML=CreateObject("Microsoft.XMLDOM")
oXML.async= "false"
oXML.load(objXML)
iPRC = oXML.getElementsByTagName("Price").item(21).text
Set oXML = Nothing
'*
Response.Write "Gold Price: $" & Round(iPRC * cOZT,4) & " per ounce"
%>
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:E7********************@comcast.com...
<TR****@hotmail.com> wrote in message
news:#c**************@TK2MSFTNGP15.phx.gbl... Almost there, but it won't read the XML data if I try HTTP:
oXML.load("http://dgcsc.org/goldprices.xml")
'* Doesn't work. I hardcoded the URL just to make sure it was calling
the correct location.
oXML.load(Server.MapPath("goldprices.xml"))
'* Works perfectly. For testing purposes I copied the goldprices.xml
file from dgcsc.org into the same directly on the server as the ASP file.
Anyone got any ideas how to get this last bit to work?
Here's the complete code:
<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit
'*
Const cOZT = 31.103477
Const cURL = "http://dgcsc.org/goldprices.xml"
'*
Dim iPRC
iPRC = 0.0000
'*
Dim oXML
Set oXML = CreateObject("Microsoft.XMLDOM")
oXML.async = "false"
'* oXML.load(cURL)
oXML.load(Server.MapPath("goldprices.xml"))
iPRC = oXML.getElementsByTagName("Price").item(21).text
Set oXML = Nothing
'*
Response.Write "Gold Price: $" & Round(iPRC * cOZT,4) & " per ounce"
%>
"oXML.load(cURL)" works for me.
How do you know "it won't read"?
Try adding this line after "oXML.load(cURL)"
Response.Write "nodeName = " & oXML.documentElement.nodeName & "<br>"
(Watch for word-wrap.)