如下:
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校验,报错“架构中根元素的错误定义”,令我无从解决,谢谢指教
解决方案 »
- 谁能帮我做个VB啊,我刚开始学
- 如何设置一个窗体,为MDI的子窗体的子窗体?
- web控件
- 救我!!datagrid不显示,急死了!
- 如何删除datagrid中高亮选中得多条纪录
- 高分请教:如何将多个只有sheet1的Excel文件合并成一个有多个sheet的Excel文件?
- 多线程里不能用sleep ??
- 关于vb中recordcount不准的问题。
- 我调用medioplayer播放文件,怎样使他自动调整大小,另外.mmcontrol中怎么使它保持显示比例,给点建议吧,各位
- 我在本站下载了一个类似于mis的软件,附有原吗,但运行是缺少arviewer.ocx,actbar.ocx,activereport,怎么会事?
- 我把问题详细说一下,为什么我的winsock1.sendata 总是出错?
- combo和text怎樣直接用代碼與數據控件鏈接
<p:person xmlns:p="http://example.com">
<familyName> KAWAGUCHI </familyName>
<firstName> Kohsuke </firstName>
</p:person>
呵呵我也不知道为什么要这样但是我可以。