VBScript错误与温度分析

VBScript错误与温度分析,vbscript,xml-parsing,Vbscript,Xml Parsing,所以我一直在尝试从weather.com解析温度,并成功地做到了这一点,但现在我一直在尝试将温度保存到一个文件temperature.txt中。我觉得这应该可以工作,但它返回错误: Line: 11 Char: 1 Error: Type mismatch: 'Write' Code: 800A000D 这是我的代码,请帮忙 Dim nm, em, FSO, oFile Set xmlDoc = CreateObject("Microsoft.XMLDOM") xmlDoc.as

所以我一直在尝试从weather.com解析温度,并成功地做到了这一点,但现在我一直在尝试将温度保存到一个文件temperature.txt中。我觉得这应该可以工作,但它返回错误:

Line: 11   Char: 1   Error: Type mismatch: 'Write'   Code: 800A000D
这是我的代码,请帮忙

Dim nm, em, FSO, oFile

Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = false
xmlDoc.load("http://xml.weather.com/weather/local/USUT0225?cc=*&unit=farenheit&dayf=0")
Set temp = xmlDoc.selectsinglenode ("/weather/dayf/day/part/t")

Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFile = FSO.OpenTextFile("temperature.txt", 2, True)

oFile.Write(temp)
oFile.Close

Set oFile = Nothing
Set FSO = Nothing
你的

顺便说一句,将节点对象分配给临时变量名。TextStream对象的.Write方法无法序列化对象,它只能写入字符串。因此,编写节点的XML内容:

oFile.Write temp.xml

然后松开这些

以进一步说明答案,因为我与您的节点有问题,所以我尝试了类似的方法

Dim nm, em, FSO, oFile

Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = false
xmlDoc.load("http://xml.weather.com/weather/local/USUT0225?cc=*&unit=farenheit&dayf=0")
Set temp = xmlDoc.selectSingleNode ("/weather/cc/tmp")

Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFile = FSO.OpenTextFile("temperature.txt", 2, True)

oFile.Write(temp.text)
oFile.Close

Set oFile = Nothing
Set FSO = Nothing

在检查temp类型时,它始终不返回任何内容。我通过链接查看了XML文件,但我看不到/weather/dayf/day/part/t,因为我在加拿大,被重定向了。无论哪种方式,我都将您要查找的节点更新为/weather/cc/tmp,并将.text输出到文件中。此时此刻,我的文本文件的内容是79

当我检查temp的类型时,它不会返回任何内容,这就是为什么会出现类型不匹配。需要找出设置温度失败的原因。感谢您的帮助。我明白你说的话,但不知道如何编排格式。但不管怎样,谢谢你,它现在起作用了!
Dim nm, em, FSO, oFile

Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = false
xmlDoc.load("http://xml.weather.com/weather/local/USUT0225?cc=*&unit=farenheit&dayf=0")
Set temp = xmlDoc.selectSingleNode ("/weather/cc/tmp")

Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFile = FSO.OpenTextFile("temperature.txt", 2, True)

oFile.Write(temp.text)
oFile.Close

Set oFile = Nothing
Set FSO = Nothing