Click to See Complete Forum and Search --> : documentElement error
jrthor2
04-01-2004, 02:39 PM
I get the following error when running this page
Microsoft VBScript runtime error '800a01a8'
Object required: 'documentElement'
<%
Option Explicit
Response.Buffer = True
Dim xml
Set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = False
xml.load ("http://www.weatherroom.com/xml/zip/17036")
Dim strTemp
strTemp = xml.documentElement.childNodes(6).text
Set xml = Nothing
%>
<html>
<head>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Temperature:</td>
<td><%=strTemp%></td>
</tr>
</table>
</body>
</html>
Can someone help
lcscne
04-01-2004, 03:48 PM
not completely sure on this but I don't think your using valid methods here with your xml object. I believe the childNodes property is associated with an XML Element. Like this:
Dim xmlDoc
Dim root
Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async = False
xmlDoc.Load ("http://www.weatherroom.com/xml/zip/17036")
If (xmlDoc.parseError.errorCode <> 0) Then
Dim myErr
Set myErr = xmlDoc.parseError
Response.Write("You have error " & myErr.reason)
Else
Set root = xmlDoc.documentElement
For i = 0 To (root.childNodes.length - 1)
Response.Write root.childNodes.Item(i).childNodes.Item(0).Text
Next
End If
jrthor2
04-01-2004, 03:55 PM
Hmm, I get the error "You have error No data is available for the requested resource."
Can you shed some light on why I get this? If you go to the url that I am loading, you get an xml document back with data in it.
lcscne
04-01-2004, 04:11 PM
Originally posted by jrthor2
Can you shed some light on why I get this?
Maybe this will help (http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q281142&ID=KB%3BEN-US%3BQ281142)
jrthor2
04-01-2004, 07:15 PM
Ok, now I get this error after altering my code a bit according to that article:
Microsoft VBScript runtime error '800a01a8'
Object required: 'childNodes.Item(...).childNodes.Item(...)'
<%
Option Explicit
Response.Buffer = True
Dim xmlDoc, i
Dim root
Set xmlDoc = Server.CreateObject("MSXML2.DOMDocument")
xmlDoc.async = False
xmlDoc.setProperty "ServerHTTPRequest", true
xmlDoc.Load ("http://www.weatherroom.com/xml/zip/17036")
If (xmlDoc.parseError.errorCode <> 0) Then
Dim myErr
Set myErr = xmlDoc.parseError
Response.Write("You have error " & myErr.reason)
Else
Set root = xmlDoc.documentElement
For i = 0 To (root.childNodes.length - 1)
Response.Write root.childNodes.Item(i).childNodes.Item(0).Text
Next
End If
%>
jrthor2
04-02-2004, 09:12 AM
Ok, getting further now. I want to define a variable for each piece of data I get back. I tried defining Location (which is the first piece of info I get back) below, but it assigns all the data to this 1 variable. I know it's because it is set to root.childNodes.Item(i).Text, but I can't get it to just show the first item (0). I try Location = root.childnOdes.Item(0).Text, but don't get anything. Below is my code.
<%
Option Explicit
Response.Buffer = True
Dim xmlDoc, i, ReturnValue, xmlDocError, root
Dim Location
Set xmlDoc = Server.CreateObject("MSXML2.DOMDocument")
xmlDoc.async = False
xmlDoc.setProperty "ServerHTTPRequest", true
ReturnValue = xmlDoc.Load ("http://www.weatherroom.com/xml/zip/17036")
If ReturnValue = False Then
Set xmlDocError = xmlDoc.ParseError
Response.Write "  " & xmlDocError.ErrorCode & " - " & xmlDocError.Reason & " URL=" & xmlDocError.URL & "<br>"
Set xmlDocError = Nothing
Else
'Response.Write xmldoc.parseError.reason
Set root = xmlDoc.documentElement
For i = 0 to (root.childNodes.length -1)
Location = root.childNodes.Item(i).Text
Response.Write Location
'Response.Write "Node " & i & "<br>"
'Response.Write root.childNodes.Item(i).childNodes.Item(0).Text
Next
End If
Set xmlDoc = Nothing
%>
jrthor2
04-02-2004, 09:19 AM
Ok, I found that the array of data starts with 1 not 0 as I thought. So, I still have an issue, I get the location now, but I get it 14 times. That's how many fields of data I get back. How do I get it just once.
Set root = xmlDoc.documentElement
For i = 0 to (root.childNodes.length -1)
Location = root.childNodes.Item(1).Text
Response.Write Location
'Response.Write "Node " & i & "<br>"
'Response.Write root.childNodes.Item(i).childNodes.Item(0).Text
Next
lcscne
04-02-2004, 10:41 AM
sorry dude, not sure what your trying to get but this works for me using a local copy of the xml file. I'm not able to get much working using the connecting to http://www.weatherroom.com/xml/zip/17036.
hope this helps.
<%
Dim xmlDoc, objRoot, i
Dim strLoc, strRecAt, strUpd, strCond, strVis, strTemp, strHum, strWind, strBar, strDew, strHeat, strWindChill, strPB, strCR
Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.Load ("C:\Inetpub\MyHome\Test\test.xml")
If xmlDoc.parseError.errorCode = 0 Then
Set objRoot = xmlDoc.documentElement
strLoc = Trim(objRoot.childNodes.Item(1).Text)
strRecAt = Trim(objRoot.childNodes.Item(2).Text)
strUpd = Trim(objRoot.childNodes.Item(3).Text)
strCond = Trim(objRoot.childNodes.Item(4).Text)
strVis = Trim(objRoot.childNodes.Item(5).Text)
strTemp = Trim(objRoot.childNodes.Item(6).Text)
strHum = Trim(objRoot.childNodes.Item(7).Text)
strWind = Trim(objRoot.childNodes.Item(8).Text)
strBar = Trim(objRoot.childNodes.Item(9).Text)
strDew = Trim(objRoot.childNodes.Item(10).Text)
strHeat = Trim(objRoot.childNodes.Item(11).Text)
strWindChill = Trim(objRoot.childNodes.Item(12).Text)
strPB = Trim(objRoot.childNodes.Item(13).Text)
strCR = Trim(objRoot.childNodes.Item(14).Text)
End If
Response.Write("<div>Location: " & strLoc & "</div>" & vbLF)
Response.Write("<div>Recorded At: " & strRecAt & "</div>" & vbLF)
Response.Write("<div>Updated: " & strUpd & "</div>" & vbLF)
Response.Write("<div>Conditions: " & strCond & "</div>" & vbLF)
Response.Write("<div>Visibility: " & strVis & "</div>" & vbLF)
Response.Write("<div>Temp: " & strTemp & "</div>" & vbLF)
Response.Write("<div>Humidity: " & strHum & "</div>" & vbLF)
Response.Write("<div>Wind: " & strWind & "</div>" & vbLF)
Response.Write("<div>Barometer: " & strBar & "</div>" & vbLF)
Response.Write("<div>Dewpoint: " & strDew & "</div>" & vbLF)
Response.Write("<div>Heat Index: " & strHeat & "</div>" & vbLF)
Response.Write("<div>Wind Chill: " & strWindChill & "</div>" & vbLF)
Response.Write("<div>Powered By: " & strPB & "</div>" & vbLF)
Response.Write("<div>Copyright: " & strCR & "</div>" & vbLF)
Set objRoot = Nothing
Set xmlDoc = Nothing
%>
jrthor2
04-02-2004, 10:59 AM
Thanks, i just got it working myself
lcscne
04-02-2004, 11:02 AM
good job
here's a better version:
<%
Dim xmlDoc, i, ReturnValue, xmlDocError, root
Dim Location
Set xmlDoc = Server.CreateObject("MSXML2.DOMDocument")
xmlDoc.async = False
xmlDoc.setProperty "ServerHTTPRequest", true
ReturnValue = xmlDoc.Load ("c:\inetpub\myhome\test\test.xml")
If ReturnValue = False Then
Set xmlDocError = xmlDoc.ParseError
Response.Write " " & xmlDocError.ErrorCode & " - " & xmlDocError.Reason & " URL=" & xmlDocError.URL & "<br>"
Set xmlDocError = Nothing
Else
'Response.Write xmldoc.parseError.reason
Set root = xmlDoc.documentElement
For i = 0 to (root.childNodes.length -1)
Location = "<div>" & root.childNodes.Item(i).NodeName
Location = Location & ": " & Trim(root.childNodes.Item(i).Text) & "</div>" & vbLF
Response.Write Location
'Response.Write "Node " & i & "<br>"
'Response.Write root.childNodes.Item(i).childNodes.Item(0).Text
Next
End If
Set root = Nothing
Set xmlDoc = Nothing
%>
here again I'm using my local copy of the xml just replace that with the url version.