我正在尝试使用MSXML 6.0 DOM对.XSD文件验证.XML文件但是在执行代码时我遇到了错误。 Tomalak在几年前得到了类似问题的答案(stackoverflow.com/questions/11708492)。我想知道:如何在以下代码片段中添加两个命名空间(objSchemaCache.Add ...)
Sub XSD_Validation()
Dim xmlDoc As MSXML2.DOMDocument60
Dim objSchemaCache As New XMLSchemaCache60
Dim objErr As MSXML2.IXMLDOMParseError
objSchemaCache.Add "http://somewhere.com/root", LoadXmlFile("I:\Test.xsd")
Set xmlDoc = LoadXmlFile("I:\Test.xml")
Set xmlDoc.Schemas = objSchemaCache
Set objErr = xmlDoc.Validate()
If objErr.errorCode = 0 Then
Debug.Print "No errors found"
Else
Debug.Print "Error parser: " & objErr.errorCode & "; " & objErr.reason
End If
End Sub
非常感谢任何帮助。
答案 0 :(得分:0)
按照以下内容。这些在这种情况下不起作用,而只是向您显示如何添加以及在何处添加。我没有看完其余的代码。
Sub XSD_Validation()
Dim xmlDoc As MSXML2.DOMDocument60
Dim objSchemaCache As New XMLSchemaCache60
Dim objErr As MSXML2.IXMLDOMParseError
' objSchemaCache.Add "http://somewhere.com/root", LoadXmlFile("I:\Test.xsd")
Set xmldoc = New MSXML2.DOMDocument60
xmldoc.setProperty "SelectionNamespaces", xmlNamespace
xmldoc.setProperty "SelectionLanguage", "XPath"
xmldoc.setProperty "SelectionNamespaces", "xmlns:content=""http://www.w3.org/2005/Atom"""
xmldoc.setProperty "SelectionNamespaces", "xmlns:other=""http://www.other.org/other/other"""
Set xmlDoc = xmlDoc.LoadXML("I:\Test.xml")
Set xmlDoc.Schemas = objSchemaCache
Set objErr = xmlDoc.Validate()
If objErr.errorCode = 0 Then
Debug.Print "No errors found"
Else
Debug.Print "Error parser: " & objErr.errorCode & "; " & objErr.reason
End If
End Sub