用微软的MSXML4。0解析XML,为什么当我的XML文件带有DTD的时候,就只能读一个根节点,它的子节点都读不出来呢?

解决方案 »

  1.   

    没有的事,我写过了完全能够浏览所有的节点,贴出你的xml和dtd,还有解析语句,大家看看!
      

  2.   

    如下:
    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校验,报错“架构中根元素的错误定义”,令我无从解决,谢谢指教