-1

Everything in this little VBS script works right up until I reach the last line of code indicated below. Upon reaching that line the script throws the error "incorrect parameter 80070057.

After spending a great deal of time googling it turns out that the error code means roughly the same thing, incorrect parameter.

'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

It is really frustrating because the .save works just 8 lines above that. Does anyone have any insight to what my problem may be and how I can solve it?

Based on the answer below I am posting the code where all of the document information gets declared:

Dim xmlFilePath6: xmlFilePath6 = "section16.xml"
Dim xmlDoc6: set xmlDoc6 = CreateObject("MSXML2.DomDocument")
xmlDoc6.async = "false"
xmlDoc6.load xmlFilePath6

This actually gets done for 6 different documents, subbing the 6 for one of the other digits 1-8. I'm still puzzled because section16.xml exists and no error is thrown on load.

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
  • What is the value of `xmlDoc6.url` at that point? Is it a valid location to save to? – RichieHindle Sep 13 '12 at 17:54
  • Yes. The file is opened successfully it just cannot be saved. – Jay Blanchard Sep 13 '12 at 18:00
  • is the file set as read only in the file attributes? – Sorceri Sep 13 '12 at 18:08
  • No, the perms of all of the xml files are the same. – Jay Blanchard Sep 13 '12 at 18:11
  • 1
    have you tried `on error resume next` and then use `err.message` to view the actual message – Sorceri Sep 13 '12 at 18:13
  • Let me give that a shot. (drat, I'm locked out of the server momentarily while they perform some maintenance) – Jay Blanchard Sep 13 '12 at 18:19
  • For whatever reason no err.message is returned and the script operates as expected when adding on error resume next – Jay Blanchard Sep 14 '12 at 13:07
  • @Sorceri That should be `err.description` (you are confusing it with C# `Exception.Message()`) – AutomatedChaos Sep 14 '12 at 16:11
  • 1
    From [another side:](http://www.perfectxml.com/msxmlAnswers.asp?Row_ID=13) _MSXML DOMDocument save method requires a file name, an ASP Response object, a DOMDocument object, or a custom object that supports persistence;_ Could it be that the `xmlDoc6.url` is not pointing to a valid _save_ domain; that would explain why you could open it, but not save it. – AutomatedChaos Sep 14 '12 at 16:21
  • 1
    In your posted code, I noticed that the line `section 16` isn't a proper comment line...the leading single quote is missing. But I presume that is a cut-and-paste error. – DavidRR Sep 15 '12 at 02:50
  • More information. The file section16.xml is saved to the server but appears it cannot be saved to. I renamed the file section16A.xml and the process started to work without any issue. No perms were changed on the file. It's very puzzling indeed. – Jay Blanchard Sep 19 '12 at 16:51
  • It is as if the name of the file is somehow not valid for the process. – Jay Blanchard Sep 19 '12 at 17:17

1 Answers1

2

UPDATE: I adjusted my code so that xmlDoc6 is no longer associated with a file and I have reproduced your error:

demo.vbs(67, 1) msxml3.dll: The parameter is incorrect.

To reproduce your error, instead of this:

xmlDoc6.load "xmlDoc6.xml"

...I initialized xmlDoc6 this way:

xmlDoc6.loadXML xmlText

Hunch: Make sure that xmlDoc6 is associated with a file. If it is not, the value of xmlDoc6.url will be the empty string.


ORIGINAL: I have written a complete program to illustrate your use case. However, I am not getting the incorrect parameter error that you report when attempting xmlDoc6.save xmlDoc6.url. But perhaps something in my program will stand out that will lead you to a solution.

For anyone interested, to run this program, copy the text to a file named say, demo.vbs, and then run it via:

cscript demo.vbs

The output to the console should look something like this:

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
DavidRR
  • 18,291
  • 25
  • 109
  • 191