BUG: The minLength attribute in an XML Schema is not validated when an attribute or element value is set to empty or null in a XML string (826753)



The information in this article applies to:

  • Microsoft XML 4.0 SP2
  • Microsoft XML 4.0 SP1
  • Microsoft XML 4.0
  • Microsoft XML 3.0 SP3
  • Microsoft XML 3.0 SP2
  • Microsoft XML 3.0 SP1
  • Microsoft XML 3.0
  • Microsoft XML 2.6
  • Microsoft XML 2.5
  • Microsoft XML 2.0

SYMPTOMS

You set an element or attribute value to empty or to null in an XML file. When you validate the contents of an XML string with an XML schema that specifies the minLength attribute as greater than zero, XML validation does not occur, and the parser error does not occur.

CAUSE

The World Wide Web Consortium (W3C) schema specification has a method to validate content that is set to empty or null. XML-Data Reduced (XDR) schema does not have this method. XDR does not validate elements or attribute values that are null or empty, and makes a choice about validation. Therefore, XDR does not validate the minLength attribute when the value of an element or attribute in an XML string is set to empty or to null.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to reproduce the behavior

  1. Paste the following code in Notepad or in a text editor of your choice:
    <?xml version="1.0" ?>
    	<Schema xmlns="urn:schemas-microsoft-com:xml-data"
    	xmlns:dt ="urn:schemas-microsoft-com:datatypes">
    	
    	<!-- min=1 and have no value -->
    	<AttributeType name="att1" dt:type="String" dt:minLength="2" />
    	<ElementType name="b" dt:minLength="2" dt:maxLength="10">
    	<datatype dt:type="string"/>
    	<attribute type="att1" />
    	</ElementType>
    </Schema>	
    
  2. Save this code as an XML schema file that is named XmlSchema.sch in the root folder (C:\inetpub\wwwroot) of your Web server.
  3. Start Notepad, and then paste the following code in the Notepad window:
    <a xmlns:x="x-schema:XmlSchema.sch">
    	<x:b x:att1=""></x:b>
    </a>
    
  4. Save this code as an XML file that is named XmlFile.xml in the root folder (C:\inetpub\wwwroot) of your Web server.
  5. Start Notepad, and then paste the following code in the Notepad window:
    <%@ Language=VBScript %>
    <HTML>
    <HEAD>XML Schema validation</HEAD>
    <BODY>
    <% 
      Dim oXML
      Dim oXmlFile
    
      Set oXML =  Server.CreateObject("MSXML2.DOMDocument.4.0")
    
      oXML.async = false
      oXML.resolveExternals = True
      oXML.validateOnParse = True
    
      oXmlFile = Server.MapPath("XmlFile.xml")
      Response.Write oXmlFile & "<br>"
    
      If not oXML.load(oXmlFile) Then
         Response.write oXML.parseError.reason 
      Else
         Response.Write oXML.Xml
      End If
    %>
    </BODY>
    </HTML>
    
  6. Save this code as TestXMLSchema.asp in the root folder of your Web server.
  7. Start Internet Explorer, type http://servername/TestXMLSchema.asp in the Address box, and then click Go. Servername is the placeholder for the name of your Web server. Notice that XML validation does not occur for the minLength attribute, and no parser error occurs.

REFERENCES

For more information about the minLength and maxLength attributes, visit the following Microsoft Developer Network (MSDN) Web site: For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

307379 HOW TO: Validate an XML Document by Using DTD, XDR, or XSD in Visual C# .NET


Modification Type:MinorLast Reviewed:7/11/2005
Keywords:kbXML kbSchema kbbug KB826753 kbAudDeveloper