【问题标题】:ADO Recordset fails to save into DOM XMLADO 记录集无法保存到 DOM XML
【发布时间】:2014-09-11 08:28:03
【问题描述】:

此记录集未能以 XML 格式保存到 DOM。

某些列数据中包含特殊字符。我可以遍历每条记录和 Response.Write() 字段而不会发生错误。

Set adoCn = Server.CreateObject("ADODB.Connection")
adoCn.Open Application("conn_string")
Set objCommand = Server.CreateObject("ADODB.Command")
Set objDOM = Server.CreateObject("Msxml2.DOMDocument.3.0")

objCommand.ActiveConnection = Application("conn_string")

spQry = "SP_QUERY"
objCommand.CommandText = spQry
objCommand.CommandType = adCmdStoredProc

Set objRs = objCommand.Execute

objRS.save objDOM, adPersistXML //Error occurs here
Set objCommand = Nothing
objRS.Close
adoCn.Close
Set objRS = Nothing

错误:未知错误

如果我在数据库中重新键入文本,从而去掉特殊字符,一切正常。

我已尝试添加以下内容以查看是否有帮助,但到目前为止没有运气:

Response.CodePage = 65001
Response.Charset="UTF-8"

有谁知道我如何将这个记录集保存到 DOM 中,不管它是否有特殊字符?

[EDIT] 添加了文字图片

[EDIT2] 执行查询后尝试流式传输记录集:

不幸的是,我对此并没有走得太远,在设置字符集时它给出了一个错误:"The parameter is incorrect",该错误实际上发生在oStream.ReadText 行上。当我注释掉字符集时,末尾的 Response.Write 只显示方括号。

Set objRs = objCommand.Execute

sXML = ""

Set oStream = Server.CreateObject("ADODB.Stream")
oStream.Charset = "utf-8" //This produced an error: The parameter is incorrect 

oRecordset.save oStream, adPersistXML
oStream.Position = 0

sXML = oStream.ReadText 

oStream.Close 
Set oStream = Nothing

Response.Write("[" & sXML & "]")

【问题讨论】:

  • 你能举出特殊字符的例子吗?
  • @oraclecertifiedprofessional 绝对参见上面的编辑,在“其他”一词的第一段末尾。我认为还有其他字符但它们不显示,因为我尝试删除刚刚提到的字符但它仍然给出错误。
  • 嗯,看着documentation 它注意到A Recordset saved in XML format is saved using UTF-8 format. When such a file is loaded into an ADO Stream, the Stream object will not attempt to open a Recordset from the stream unless the Charset property of the stream is set to the appropriate value for UTF-8 format. 我想知道您的特殊字符是否会导致在不受支持的字符集中创建流。您可以尝试改用ADODB.Stream,它允许您显式声明目标字符集。
  • 试了一下流,但没有走得很远,也许你可以帮我举个例子。请参阅上面的 Edit2。
  • 抱歉,我想我必须安装不同版本的 ADODB,因为我无法重现该错误。我发现了这个问题的othermentions(似乎与使用“智能”引号从Office 文档中复制'n 粘贴有关)但没有解决方案

标签: xml dom vbscript asp-classic adodb


【解决方案1】:

我找不到显示数据的方法。所以我手动更改了数据库中的文本,因为只有 4 条记录。

当表单数据被处理、插入或更新时,我最终在数据输入端解决了这个问题。

我遍历文本,分析每个字符,去除所有非键盘字符,生成一个干净的字符串。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多