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

Article translations Article translations
Article ID: 826753 - View products that this article applies to.
Expand all | Collapse all

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

Properties

Article ID: 826753 - Last Review: January 17, 2007 - Revision: 2.1
APPLIES TO
  • Microsoft XML Core Services 4.0
  • Microsoft XML Core Services 4.0 Service Pack 1
  • Microsoft XML Core Services 4.0
  • Microsoft XML Parser 3.0 Service Pack 3
  • Microsoft XML Parser 3.0 Service Pack 2
  • Microsoft XML Parser 3.0 Service Pack 1
  • Microsoft XML Parser 3.0
  • Microsoft XML Parser 2.6
  • Microsoft XML Parser 2.5
  • Microsoft XML Parser 2.0
Keywords: 
kbxml kbschema kbbug KB826753

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com