以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 XML基础 』  (http://bbs.xml.org.cn/list.asp?boardid=1)
----  斑竹救人啦!!  (http://bbs.xml.org.cn/dispbbs.asp?boardid=1&rootid=&id=7941)


--  作者:chivalry
--  发布时间:5/29/2004 3:39:00 PM

--  斑竹救人啦!!
小弟才接触XML不久,遇到一个问题
Dim xmlDoc As MSXML2.DOMDocument

Private Sub Command1_Click()
Dim filename As String
Dim msg As String
Dim retval As Long

CommonDialog1.Filter = "XML files | *.xml"
CommonDialog1.ShowOpen

If CommonDialog1.filename = "" Then Exit Sub

xmlDoc.async = False

If optWellFormedOnly.Value = True Then
   xmlDoc.validateOnParse = False
Else
   xmlDoc.validateOnParse = True
End If

xmlDoc.Load CommonDialog1.filename


If xmlDoc.parseError.errorCode <> 0 Then
   msg = "Error on line " & xmlDoc.parseError.Line & vbCrLf
   msg = msg & xmlDoc.parseError.srcText & vbCrLf
   msg = msg & xmlDoc.parseError.reason
   MsgBox msg
   Exit Sub
End If

If optValidateAlso.Value = True Then
   retval = xmlDoc.Validate
   If retval <> 0 Then
      msg = CommonDialog1.filename & "is well formed." & vbCrLf
      msg = msg & "However it contains no DTD or schema reference" _
          & vbCrLf
      msg = msg & "and so cannot be validated."
   Else
      msg = CommonDialog1.filename & "is well formed and valid." & _
          vbCrLf
   End If
Else
   msg = CommonDialog1.filename & "is well formed." & vbCrLf
End If

MsgBox msg

End Sub

Private Sub Command2_Click()
Dim msg As String
On Error Resume Next

Set xmlDoc = New DOMDocument

If Err Then
   msg = "DOMDocument object could not be created." & vbCrLf
   msg = msg & "Program will terminate."
   MsgBox msg
   Unload Me
End If

End Sub

这是个验证XML文档良构性和有效性的程序(照书打上去的)
但运行时提示“Object variable or with block variable not set" 为什么呢。。。。
不懂呀。。。。


--  作者:chivalry
--  发布时间:5/29/2004 3:40:00 PM

--  
运行到红字的地方出的错
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
62.500ms