-1

这个小 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 个不同的文档完成的,将 6 替换为其他数字 1-8 之一。我仍然感到困惑,因为 section16.xml 存在并且加载时没有抛出错误。

4

1 回答 1

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
于 2012-09-15T02:59:27.720 回答