【问题标题】:ASP classic: Object required: 'objContent.documentElement'ASP 经典:需要对象:'objContent.documentElement'
【发布时间】:2013-10-05 06:21:21
【问题描述】:

我正在开发一个使用 ASP 经典的项目。我遇到了这个错误:

Microsoft VBScript 运行时错误“800a01a8”

需要对象:'objContent.documentElement'

/muhproject/includes/clsTransform.asp,第 138 行

如何根据需求将objContent.documentElement 包含到项目中?

文件的第138行如下:

'Attach fragment into pageContentXML
objContent.documentElement.appendChild xDoc2.documentElement

编辑:这是代码的完整功能

'TransformContent - accepts content in XML data, and contentXSL file path
    public function TransformContent(scriptNameFull, fragmentXML)

        fragmentXML = decodeUTF8(fragmentXML)

        '1. Load the content.html (as XML)
        Dim objContent
        set objContent = Server.CreateObject("Msxml2.DOMDocument.3.0")  

        Dim contentXSLSpec
        contentXSLSpec = rootRel & "/muhproject/template/page/content.xsl"  'this is fixed

        objContent.async = false
        objContent.validateOnParse = false
        objContent.load( server.MapPath(scriptNameFull) )

        '2. Load fragmentXML XML fragment
        Dim xDoc2
        set xDoc2 = Server.CreateObject("Msxml2.DOMDocument.3.0")
        xDoc2.Async = false
        xDoc2.resolveExternals = false
        xDoc2.validateOnParse = false
        xDoc2.loadXML(fragmentXML)


        '3. Attach fragment into pageContentXML
        objContent.documentElement.appendChild xDoc2.documentElement

        Dim objXSL
        set objXSL = Server.CreateObject("Msxml2.DOMDocument.3.0")

        objXSL.async = false
        objXSL.validateOnParse = false

        objXSL.load( server.mapPath(contentXSLSpec) )

        '3. Do the transformation

        Dim retVal
        retVal = objContent.transformNode(objXSL.documentElement)

        set objContent = nothing
        set xDoc2 = nothing
        set objXSL = nothing

        TransformContent = retVal

    end function

【问题讨论】:

  • 我认为我们需要看看您是如何创建该对象的 objContent 。你能再显示一些代码吗,/
  • @SearchAndResQ 我已经编辑了问题
  • 我猜你的 XML 有问题;你也可以显示 XML 吗?
  • 检查布尔返回值到xDoc2.loadXML(fragmentXML) 以查看XML 是否正确加载,如果没有则检查xDoc2.parseError
  • 另外,如果您的documentFragment 实际上是一个文档片段(例如它没有单个根元素),请考虑使用createDocumentFragment()

标签: asp-classic vbscript


【解决方案1】:

为了推动 oracle 的论点:

除去所有偶然因素,您的脚本是:

Option Explicit

Dim objContent : Set objContent = CreateObject("Msxml2.DOMDocument.3.0")
objContent.load "nosuch.xml"
objContent.documentElement.appendChild "pipapo"

输出:

cscript 18732533.vbs
...\18732533.vbs(5, 1) Microsoft VBScript runtime error: Object required: 'ocumentElement'

如果您遵循“通过检查错误确保您的乐观假设!”规则,您的脚本将如下所示:

Option Explicit

Dim objContent : Set objContent = CreateObject("Msxml2.DOMDocument.3.0")
objContent.load "nosuch.xml"
If 0 = objContent.ParseError Then
   objContent.documentElement.appendChild "pipapo"
Else
   WScript.Echo objContent.ParseError.Reason
End If

输出:

cscript 18732533.vbs
The system cannot locate the resource specified.

(分别是关于现有文件格式不正确的一些信息)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 1970-01-01
    • 2010-11-14
    • 2011-11-17
    相关资源
    最近更新 更多