FIX: XmlSchema Object Incorrectly Permits Invalid Local Elements in an XSD Schema (317415)



The information in this article applies to:

  • Microsoft XML Classes (included with the .NET Framework 1.0)

This article was previously published under Q317415

SYMPTOMS

If an XSD schema has invalid local elements, the XmlSchema object loads the invalid elements as valid and does not generate an error.

RESOLUTION

When you write XSD schemas, make sure that they comply with World Wide Web Consortium (W3C) specifications. The W3C specification for XSD schemas is available at the following W3C Web site:

STATUS

This bug was corrected in Microsoft .NET Framework Class Libraries 1.1.

MORE INFORMATION

The W3C specification defines the XML schema definition language, which offers facilities for describing the structure and constraining the contents of XML 1.0 documents, including those that exploit the XML Namespace facility. The schema language, which is itself represented in XML 1.0 and uses namespaces, substantially reconstructs and extends the capabilities found in XML 1.0 document type definitions (DTDs). For more information, see the following W3C Web site:

Steps to Reproduce the Behavior

  1. Paste the following XSD schema in a text file, and then save the file as C:\test.xsd:
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://testuc" xmlns:ns="http://testuc">
    
    <xsd:complexType name="myType">
     <xsd:all>
      <xsd:element name="elt" type="xsd:string"/>
      <xsd:element name="test" type="xsd:string" abstract="true" block="#all"/>
     </xsd:all>
    </xsd:complexType>
    
    <xsd:element name="root" type="ns:myType"/>
    
    </xsd:schema>
    					
  2. Create a new Visual Basic Windows Application project.
  3. Drag a Button control from the toolbox to Form1.
  4. Paste the following code in the Click event of Button1:
     Dim fstream As New FileStream("C:\test.xsd", FileMode.Open)
     myschema = New XmlSchema()
     myschema = XmlSchema.Read(fstream, Nothing)
     myschema.Compile(AddressOf ValidationEventHandler)
     MessageBox.Show("Completed Loading XSD Schema")
    					
  5. Paste the following Sub routine:
    Public Sub ValidationEventHandler(ByVal sender As Object, ByVal e As ValidationEventArgs)
          MsgBox(e.Message)
    End Sub
    					
  6. Save and then run the project. You receive the message "Completed Loading XSD Schema".

    Note that the XSD schema has a element named "test" with a Abstract property that is set to "true"; according to W3C specifications for local elements, this should always be "false".

Modification Type:MajorLast Reviewed:9/22/2003
Keywords:kbbug kbpending KB317415