程序:
dim xmlDoc as DomDocument
set xmlDoc = new DomDocument
xmlDoc.load "C:\config.xml"
问题:
程序运行后,
跟踪 xmlDoc.documentElement 的值总是为
xmlDoc.documentElement is Nothing
是什么原因?

解决方案 »

  1.   

    你看看你的xml符合xml规范不??用ie打开看看
      

  2.   

    我的配置文件内容如下
     <?xml version="1.0" encoding="ISO-8859-1"?>
    <config>
    <name>pathname</name>
    <value>conf/tomcat-users.xml</value>
    </config>现在运行后,还是
    xmlDoc.documentElement is Nothing
      

  3.   

    <?xml version="1.0" encoding="gb2312" ?>换个编码方式
      

  4.   

    Load 后要检查 xmlDoc.parseError 是否成功,这是基本规则
      

  5.   

    Public Sub LoadDocument(sFile As String)
       
        Dim xDoc As MSXML2.DOMDocument
        Set xDoc = New MSXML2.DOMDocument
        xDoc.validateOnParse = False  '这行用TRUE也试试
         
        If xDoc.Load(sFile) Then     
            ' The document loaded successfully.
            ' Now do something intersting.     
        Else
        
            Dim strErrText As String
            Dim xPE As MSXML2.IXMLDOMParseError
             
            ' ?得parseError?象
            Set xPE = xDoc.parseError
             
            With xPE
             
                strErrText = " XML Document 不能LOAD " & _
                "原因是." & vbCrLf & _
                "error: " & .errorCode & ": " & xPE.reason & vbCrLf & _
                "Line #: " & .Line & vbCrLf & _
                "Line Position: " & .linepos & vbCrLf & _
                "Position In File: " & .filepos & vbCrLf & _
                "Source Text: " & .srcText & vbCrLf & _
                "Document URL: " & .url
             
            End With
                       
            MsgBox strErrText, vbExclamation
            Set xPE = Nothing
            
        End If
       
    End Sub
      

  6.   

    一个解析XML的VB类:
    http://www.cnblogs.com/happy-wangtao/archive/2006/12/24/602030.aspx