Tomas Beblar
Tomas Beblar

Reputation: 555

VBscript Record set w/ XML data outputting as byte array. Microsoft VBScript runtime error: Invalid procedure call or argument

sub generateCategoryXML_helper()

dim FSO, fileOut
set FSO = CreateObject("Scripting.FileSystemObject")
set fileOut = FSO.CreateTextFile(Server.MapPath("categoryTree.xml"), True)

fileOut.WriteLine("<?xml version=""1.0"" encoding=""UTF-8""?>")

set RS_categoryXML = callStoredProcedure("generateCategoryXML", null) 

while not RS_categoryXML.EOF

    fileOut.Write(RS_categoryXML(0))

    RS_categoryXML.MoveNext

wend

end sub

The fileOut.Write(RS_categoryXML(0)) throws an error: Microsoft VBScript runtime error: Invalid procedure call or argument

RS_categoryXML(0) contains an XML doc. RS_categoryXML(0) stored as a byte array. Why? It should be a long string that I can write to the file but for some reason it's stored as a byte array and fails to output.

Thanks,

Tomas

Upvotes: 0

Views: 553

Answers (1)

AnthonyWJones
AnthonyWJones

Reputation: 189457

RS_categoryXML(0) stored as a byte array. Why?

You haven't shown us anything relevant to that so its difficult to say. We have no idea what SQL is in the "generateCategoryXML" or even what database engine you are using (including its version).

That said I'll guess what you have as byte array containing the xml already encoded to UTF8. I'll also guess that there is only ever one record in the recordset (else the XML you are attempting to create will be missing a root element).

Another problem you have is you are attempting to use FSO to write a UTF8 encoded XML file but FSO can't handle UTF8.

My advice would be drop the use of FSO and switch to ADODB.Stream instead, that will allow you to write the bytes directly to the stream and save the file. I wouldn't even bother with the xml declaration its only really useful when specifying an encoding different from UTF8.

Upvotes: 1

Related Questions