更新:我调整了我的代码,使其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