1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
<html dir="ltr"><head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META HTTP-EQUIV="assetid" CONTENT="HV06246467"><META NAME="lcid" CONTENT="1033"><title>Schema-based validation in the Data Validation developer sample form</title><link rel="stylesheet" type="text/css" href="office10.css"><script type="text/javascript" language="Javascript" src="ExpCollapse.js"></script><script type="text/javascript" language="JavaScript" src="inline.js"></script></head><body><p id="ExpandAllLine" class="ExpFav"><a href="#" onclick="ExpandAll()" onkeypress="ExpandAll()" class="DropDown"><img id="picHeader" border="0" src="expandtri.gif" alt="Show All"><span id="ExpandAll">Show All</span></a></p><h1>Schema-based validation in the Data Validation developer sample form</h1><div class="ofvbanav"><span class="ofvbanavreuse" id="seealso" onclick="toggleList()" onkeypress="toggleList()"></span><span class="ofvbanavreuse" id="specifics" onclick="toggleList()" onkeypress="toggleList()"></span></div><p>Schema-based <a href="#" class="glossary" onclick="AppendPopup(this,'xddatavalidation')" onkeypress="AppendPopup(this,'xddatavalidation')">data validation</a> in Microsoft Office InfoPath 2003 is determined by the <a href="#" class="glossary" onclick="AppendPopup(this,'OfXmlSchemas')" onkeypress="AppendPopup(this,'OfXmlSchemas')">XML Schema</a> associated with a form. Schema-based validation occurs by default whenever a user fills out a form. After the user enters data into a field and moves out of that field, the data is immediately checked against the XML Schema.</p><p>In the Data Validation developer sample form, schema-based validation is used to verify that a number falls within a certain range, verify the type of data in a field, verify that a field contains data, and limit the number of rows that can be added to a table.</p><p><b>Note</b>
InfoPath
supports the creation of only data type and required field constraints in XML Schemas
in <a href="#" class="glossary" onclick="AppendPopup(this,'xddesignmode')" onkeypress="AppendPopup(this,'xddesignmode')">design mode</a>.
However,
the use of other kinds of constraints in the schema is supported. To create other kinds of schema-based validation, you must edit your XML Schema files using Microsoft Notepad or some other text editor. </p><p><a href="#" class="DropDown" onclick="Outline2()" onkeypress="Outline2()"><img border="0" src="blueup.gif" alt="Show">Range checking and data-type validation in the schema</a></p><div id="ExpCol" class="collapsed" border="0"><p>In the Data Validation developer sample form, the XML Schema defines the validNumber field with the <b class="bterm">float</b> data type and the range of acceptable values as between 1 and 50 (inclusive). The following is the section of the XML Schema in the sample form's schema.xsd file that defines the validNumber field and its validation constraints (restrictions):</p><pre><code><xsd:simpleType name="validNumber">
<xsd:restriction base="xsd:float">
<xsd:maxInclusive value="50"/>
<xsd:minInclusive value="1"/>
</xsd:restriction>
</xsd:simpleType></code></pre><p>If the value entered is not valid, the field is marked with an <a href="#" class="glossary" onclick="AppendPopup(this,'xdinlinealert')" onkeypress="AppendPopup(this,'xdinlinealert')">inline alert</a>. If the user rests the mouse pointer on the field, additional information appears. The user can right-click the field and click <b class="ui">Full error description</b> on the shortcut menu
to see more detailed information.
The user may save the form even if the error is not corrected,
but the inline alert will continue to appear each time the form is opened until the error is corrected.</p><p>InfoPath provides a set of default error messages that are used when validating data based on an XML Schema. However, InfoPath also provides the capability to override these default error messages with custom error messages that are specific to the type of validation constraints that are used within a given form. To override the default error messages, you must directly modify the <a href="#" class="glossary" onclick="AppendPopup(this,'xdformdefinitionfilexsf')" onkeypress="AppendPopup(this,'xdformdefinitionfilexsf')">form definition (.xsf) file</a>
and associate the error message text with a particular field in the schema using an
<b class="bterm"><a href="xsfelmoverride.htm" id="HV01021492" lcid=" ">override</a></b> element with a nested <a href="xsfelmerrorMessage.htm" id="HV01021474" lcid=" "><b class="bterm">errorMessage</b></a> element. In the case of the validNumber field in the Data Validation developer sample form, the following <b class="bterm">override</b>
element was added to the .xsf
file as a <a href="#" class="glossary" onclick="AppendPopup(this,'xdchildelement')" onkeypress="AppendPopup(this,'xdchildelement')">child element</a> of the <b class="bterm"><a href="xsfelmschemaErrorMessages.htm" id="HV01021499" lcid=" ">schemaErrorMessages</a></b> element:</p><pre><code><xsf:schemaErrorMessages>
<xsf:override match="/sampleData/number">
<xsf:errorMessage
shortMessage="Invalid Number.">
The value entered must be a valid number between 1 and 50.
</xsf:errorMessage>
</xsf:override>
...
</xsf:schemaErrorMessages>
</code></pre><p><b>Note</b> Modification of the .xsf
file to override the default data validation error messages and add custom data validation error messages is
required only with
schema-based data validation. When you use custom or script-based validation, you can use the <b class="ui">Data Validation</b> dialog box to add custom data validation messages.</p></div><p><a href="#" class="DropDown" onclick="Outline2()" onkeypress="Outline2()"><img border="0" src="blueup.gif" alt="Show">Required fields in the schema</a></p><div id="ExpCol" class="collapsed" border="0"><p>If the XML Schema specifies that a
particular field in an InfoPath form is required, an error message appears when the user saves or submits the form if that field was left blank. In the Data Validation developer sample form, a <b class="bterm">nonEmptyString</b> data type is defined in the schema.
It is used as the data type for the favoriteColor field in the sample form:</p><pre><code><xsd:simpleType name="nonEmptyString">
<xsd:restriction base="xsd:string">
<xsd:minLength value="1"/>
</xsd:restriction>
</xsd:simpleType>
</code></pre><p>Here, the type <b class="bterm">nonEmptyString</b>, derived from <b class="bterm">simpleType</b>, has been made required by setting a <b class="bterm">minLength</b> value of 1.</p></div><p><a href="#" class="DropDown" onclick="Outline2()" onkeypress="Outline2()"><img border="0" src="blueup.gif" alt="Show">Structural validation in the schema</a></p><div id="ExpCol" class="collapsed" border="0"><p>Unlike the other types of data validation available in InfoPath, structural validation <i>prevents</i> the user from making validation errors. Instead of allowing the structure to become invalid (allowing too many rows in a data table, for example) and responding with an error, structural validation disables any action that could create an invalid structure. The most common type of structural constraint in InfoPath
occurs in repeating rows and items with schema-defined minimums and maximums.</p><p>In the Data Validation developer sample form, the following structural constraint is defined in the XML Schema and is used for the structural repeating table in the form:</p><pre><code><xsd:element name="listA">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="itemA" minOccurs="1" maxOccurs="2"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</code></pre><p>In this case, the user is not allowed to add more than two <b class="bterm">listA</b> elements (which is the list of blocks), nor can the user delete the last instance of a <b class="bterm">listA</b> element. To the user, this constraint requires a table of no more than two and no fewer than one data-bound rows.</p><p><b>Note</b> Custom error messages cannot be implemented when using structural validation in the XML Schema.</p></div><script type="text/javascript" language="JScript" src="ofvbanl.js"></script><span id="ofVBAISpan" class="ofvbaispan"><iframe id="ofVBAIFrame" frameborder="0" marginheight="0" marginwidth="4" scrolling="auto" width="100%" src="../links/inconSchemaValInDVForm_l.htm"></iframe></span><center><a href="XMLSchemaCopyright_HV01147162.htm">©2003-2004 Microsoft Corporation. All rights reserved.</a>
Permission to copy, display and distribute this document is available at: <a
href="http://r.office.microsoft.com/r/rlidAWSContentRedir?AssetID=XT010988631033&CTT=11&Origin=HV011232471033"
target="_new">http://msdn.microsoft.com/library/en-us/odcXMLRef/html/odcXMLRefLegalNotice.asp</a></center></body></html>
|