这个小VBS脚本中的所有内容都可以正常工作,直到我到达下面指出的最后一行代码。到达该行后,脚本会抛出错误“错误参数80070057。
花了很多时间谷歌后发现错误代码意味着大致相同的事情,不正确的参数。
'section 15
Set lots = xmlDoc3.selectNodes("ArrayOfLot/Lot")
For Each lot in lots
Dim nl: Set nl = lot.cloneNode(true)
xmlDoc4.documentElement.appendChild nl
Next
xmlDoc4.save xmlDoc4.url 'this code works
'**************************************************************************
'section 16
Set lots = xmlDoc5.selectNodes("ArrayOfLot/Lot")
For Each lot in lots
Dim nll: Set nll = lot.cloneNode(true)
xmlDoc6.documentElement.appendChild nll
Next
xmlDoc6.save xmlDoc6.url 'this does not work - error thrown
这真是令人沮丧,因为.save仅比它高出8行。有没有人对我的问题可能是什么以及如何解决它有任何见解?
基于下面的答案,我发布了声明所有文档信息的代码:
Dim xmlFilePath6: xmlFilePath6 = "section16.xml"
Dim xmlDoc6: set xmlDoc6 = CreateObject("MSXML2.DomDocument")
xmlDoc6.async = "false"
xmlDoc6.load xmlFilePath6
这实际上是针对6个不同的文档完成的,为其他数字1-8之一分配6。我仍然感到困惑,因为section16.xml存在且加载时不会抛出任何错误。
答案 0 :(得分:2)
更新:我调整了代码,以便xmlDoc6
不再与文件相关联,并且我已经重现了您的错误:
demo.vbs(67, 1) msxml3.dll: The parameter is incorrect.
重现错误,而不是:
xmlDoc6.load "xmlDoc6.xml"
...我用这种方式初始化xmlDoc6
:
xmlDoc6.loadXML xmlText
预感:确保xmlDoc6
与文件相关联。如果不是,则xmlDoc6.url
的值将为空字符串。
原文:我编写了一个完整的程序来说明您的用例。但是,我在尝试incorrect parameter
时未收到您报告的xmlDoc6.save xmlDoc6.url
错误。但是,我的计划中的某些内容可能会脱颖而出,从而引导您找到解决方案。
对于任何感兴趣的人,要运行此程序,请将文本复制到名为say demo.vbs
的文件中,然后通过以下方式运行:
cscript demo.vbs
控制台的输出应如下所示:
Creating XML documents 3 through 6.
Saving file:///c:/Users/DavidRR/temp/xmlDoc4.xml
Saving file:///c:/Users/DavidRR/temp/xmlDoc6.xml
Done.
' demo.vbs - Use MSXML to edit and save multiple XML files.
Option Explicit
Dim xmlText : xmlText = "" _
& "<?xml version='1.0' encoding='utf-8'?>" _
& "<ArrayOfLot>" _
& " <Lot>" _
& " Lot One" _
& " </Lot>" _
& " <Lot>" _
& " Lot Two" _
& " </Lot>" _
& " <Lot>" _
& " Lot Three" _
& " </Lot>" _
& "</ArrayOfLot>" _
& ""
WScript.Echo "Creating XML documents 3 through 6."
Dim xmlDoc3 : Set xmlDoc3 = CreateObject("Msxml2.DOMDocument")
Dim xmlDoc4 : Set xmlDoc4 = CreateObject("Msxml2.DOMDocument")
Dim xmlDoc5 : Set xmlDoc5 = CreateObject("Msxml2.DOMDocument")
Dim xmlDoc6 : Set xmlDoc6 = CreateObject("Msxml2.DOMDocument")
xmlDoc3.loadXML xmlText
If xmlDoc3.parseError.errorCode <> 0 Then
WScript.Echo "Couldn't load xmlDoc3: " & xmlDoc3.parseError.reason
WScript.Quit(1)
Else
' WScript.Echo "Loaded XML [" & xmlDoc3.documentElement.xml & "]"
End If
' WScript.Echo xmlDoc3.Xml
xmlDoc3.save "xmlDoc4.xml"
xmlDoc3.save "xmlDoc5.xml"
xmlDoc3.save "xmlDoc6.xml"
xmlDoc4.load "xmlDoc4.xml"
xmlDoc5.load "xmlDoc5.xml"
xmlDoc6.load "xmlDoc6.xml"
' xmlDoc6.loadXML xmlText
' WScript.Echo "xmlDoc6.url = [" & xmlDoc6.url & "]"
' section 15
Set lots = xmlDoc3.selectNodes("ArrayOfLot/Lot")
' WScript.Echo lots.length
Dim lot, lots
For Each lot In lots
Dim nl: Set nl = lot.cloneNode(True)
xmlDoc4.documentElement.appendChild nl
Next
WScript.Echo "Saving " & xmlDoc4.url
xmlDoc4.save xmlDoc4.url 'this code works
'**************************************************************************
' section 16
Set lots = xmlDoc5.selectNodes("ArrayOfLot/Lot")
For Each lot in lots
Dim nll: Set nll = lot.cloneNode(true)
xmlDoc6.documentElement.appendChild nll
Next
WScript.Echo "Saving " & xmlDoc6.url
xmlDoc6.save xmlDoc6.url ' reportedly does not work...but it works here.
Set xmlDoc6 = Nothing
Set xmlDoc5 = Nothing
Set xmlDoc4 = Nothing
Set xmlDoc3 = Nothing
WScript.Echo "Done."
' End