VBscript 记录集,带有以字节数组形式输出的 XML 数据。 Microsoft VBScript 运行时错误:无效的过程调用或参数
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
fileOut.Write(RS_categoryXML(0)) 引发错误: Microsoft VBScript 运行时错误:无效的过程调用或参数
RS_categoryXML(0) 包含 XML 文档。 RS_categoryXML(0) 存储为字节数组。为什么?它应该是一个长字符串,我可以写入文件,但由于某种原因它存储为字节数组并且无法输出。
谢谢,
托马斯
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有向我们展示任何与此相关的内容,所以很难说。我们不知道“generateCategoryXML”中的 SQL 是什么,甚至不知道您正在使用什么数据库引擎(包括其版本)。
也就是说,我会猜测您的字节数组包含已编码为 UTF8 的 xml。我还猜测记录集中只有一条记录(否则您尝试创建的 XML 将缺少根元素)。
您遇到的另一个问题是您尝试使用 FSO 编写 UTF8 编码的 XML 文件,但 FSO 无法处理 UTF8。
我的建议是放弃使用 FSO 并改用 ADODB.Stream,这样您就可以将字节直接写入流并保存文件。我什至不会理会 xml 声明,它只有在指定与 UTF8 不同的编码时才真正有用。
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.