如下: XSD文件 <xs:schema targetNamespace="http://example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="familyName" type="xs:string"/> <xs:element name="firstName" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>XML文件 <person xmlns="http://example.com"> <familyName> KAWAGUCHI </familyName> <firstName> Kohsuke </firstName> </person>VB代码 Private Sub Command3_Click() Dim xs 'Create a schema cache and add books.xsd to it. Dim xmlschema As MSXML2.XMLSchemaCache Set xmlschema = New MSXML2.XMLSchemaCache xmlschema.Add "", App.Path & "\Untitled2.xsd" 'Create an XML DOMDocument object. Dim xmldom As MSXML2.DOMDocument Set xmldom = New MSXML2.DOMDocument 'Assign the schema cache to the DOM document. 'schemas collection. Set xmldom.schemas = xmlschema 'Load books.xml as the DOM document. xmldom.async = False xmldom.Load App.Path & "\Untitled1.xml" 'Return validation results in message to the user. If xmldom.parseError.errorCode <> 0 Then MsgBox xmldom.parseError.errorCode & " " & _ xmldom.parseError.reason Else MsgBox "No Error" End If End Sub 我用以上代码进行schema校验,报错“架构中根元素的错误定义”,令我无从解决,谢谢指教
XSD文件
<xs:schema targetNamespace="http://example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="familyName" type="xs:string"/>
<xs:element name="firstName" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>XML文件
<person xmlns="http://example.com">
<familyName> KAWAGUCHI </familyName>
<firstName> Kohsuke </firstName>
</person>VB代码
Private Sub Command3_Click()
Dim xs
'Create a schema cache and add books.xsd to it.
Dim xmlschema As MSXML2.XMLSchemaCache
Set xmlschema = New MSXML2.XMLSchemaCache
xmlschema.Add "", App.Path & "\Untitled2.xsd" 'Create an XML DOMDocument object.
Dim xmldom As MSXML2.DOMDocument
Set xmldom = New MSXML2.DOMDocument 'Assign the schema cache to the DOM document.
'schemas collection.
Set xmldom.schemas = xmlschema 'Load books.xml as the DOM document.
xmldom.async = False
xmldom.Load App.Path & "\Untitled1.xml" 'Return validation results in message to the user.
If xmldom.parseError.errorCode <> 0 Then
MsgBox xmldom.parseError.errorCode & " " & _
xmldom.parseError.reason
Else
MsgBox "No Error"
End If
End Sub
我用以上代码进行schema校验,报错“架构中根元素的错误定义”,令我无从解决,谢谢指教