Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 826753 - Last Review: January 17, 2007 - Revision: 2.1
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
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.
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.
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed at the beginning of this article.
Steps to reproduce the behavior
- 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>
- Save this code as an XML schema file that is named
XmlSchema.sch in the root folder (C:\inetpub\wwwroot) of your Web
server.
- 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>
- Save this code as an XML file that is named XmlFile.xml in
the root folder (C:\inetpub\wwwroot) of your Web server.
- 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>
- Save this code as TestXMLSchema.asp in the root folder of
your Web server.
- 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.
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Â
(http://kbalertz.com/Feedback.aspx?kbNumber=307379/
)
HOW TO: Validate an XML Document by Using DTD, XDR, or XSD in Visual C# .NET
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
| kbxml kbschema kbbug KB826753 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate