Microsoft KB Archive/827006

= How to modify an external schema for an InfoPath form =

Article ID: 827006

Article Last Modified on 4/18/2007

-

APPLIES TO


 * Microsoft Office InfoPath 2007
 * Microsoft Office InfoPath 2003

-



IN THIS TASK

 * SUMMARY
 * Create the External Schema
 * Create an InfoPath Form That Is Based on an External Schema
 * Modify the Schema
 * Troubleshooting



SUMMARY
When you design a form that is based on an external schema, Microsoft Office InfoPath 2007, or Microsoft Office InfoPath 2003 assumes that the schema is finalized and therefore prevents any modification of the schema in the Data Source task pane. If you must edit an external schema, you can do this by using a text editor or an XML editor. This article describes how to design an InfoPath form that is based on an external schema and how to manually modify the external schema.

NoteInfoPath 2003 Service Pack 1 adds the Convert Main Data Source command to the Tools menu in InfoPath Designer. This command permits you to change or to update the external schema that is used by an InfoPath form template without using a text editor or an XML editor.

back to the top

Create an External Schema
 Start InfoPath. Create a new blank form. To design the schema, follow these steps:  In the Data Source task pane, right-click myFields, and then click Properties. In the Field or Group Properties dialog box, change the name from myFields to Customers, and then click OK. Right-click Customers, and then click Add. In the Add Field or Group dialog box, set the Name property to CustomerID, and then click OK. Repeat the previous steps to add a CustomerName field, an Address field, a City field, a State field, and a ZipCode field to the Customers group.</li></ol> </li> Save the template as Schema1.xsn .</li> In InfoPath 2007, click Save as Source Files on the File menu, and then select a folder to save the extracted files to.

In InfoPath 2003, click Extract Form Files on the File menu, and then select a location to save the extracted files to.</li> Close Schema1, but do not exit InfoPath.</li></ol>

back to the top

InfoPath 2007

 * 1) On the File menu, click Design a Form Template.
 * 2) In the Design a Form Template task pane, click XML or Schema, and then click OK. The Data Source Wizard appears.
 * 3) Click Browse, move to the location to which the form files were extracted in step 4 of the &quot;Create an External Schema&quot; section, select the Myschema.xsd file, and then click Next.
 * 4) Click No, and then click Finish to complete the wizard.
 * 5) In the Data Source task pane, try to add elements to the data source or try to delete elements from the data source. Notice that the data source is read-only.
 * 6) Save this template as ExtSchema.xsn.

InfoPath 2003

 * 1) On the File menu in InfoPath, click Design a Form.
 * 2) In the Design a Form task pane, click New from Data Source.

This starts the Data Source Setup Wizard.
 * 1) Select XML Schema or XML data file, and then click Next.
 * 2) Move to the location where the form files were extracted to in step 4 of the previous section, select the Myschema.xsd file, and then click Finish.
 * 3) In the Data Source task pane, try to add elements or try to delete elements from the data source.

Notice that the data source is read-only.
 * 1) Save this template as ExtSchema.xsn.

back to the top

Modify the Schema
<ol> Make sure that the ExtSchema template is open in InfoPath.</li> In InfoPath 2007, click Save as Source Files on the File menu, to extract the files.

In InfoPath 2003, click Extract Form Files on the File menu to extract the files.</li> Exit InfoPath.</li>  Move to the folder on the computer where the ExtSchema template files were extracted to, and then open the Myschema.xsd file.

To open the Myschema.xsd file, you can use a text editor such as Notepad or an XML Editor such as Microsoft Visual Studio .NET. The schema appears in the editor as follows:

Note The actual namespaces in your <xsd:schema> element may vary. <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?> <xsd:schema targetNamespace= &quot;http://schemas.microsoft.com/office/infopath/2003/myXSD/2003-09-16T19:01:29&quot; xmlns:my=&quot;http://schemas.microsoft.com/office/infopath/2003/myXSD/2003-09-16T19:01:29&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;> <xsd:element name=&quot;Customers&quot;> <xsd:complexType> <xsd:sequence> <xsd:element ref=&quot;my:CustomerID&quot; minOccurs=&quot;0&quot;/> <xsd:element ref=&quot;my:CustomerName&quot; minOccurs=&quot;0&quot;/> <xsd:element ref=&quot;my:Address&quot; minOccurs=&quot;0&quot;/> <xsd:element ref=&quot;my:City&quot; minOccurs=&quot;0&quot;/> <xsd:element ref=&quot;my:State&quot; minOccurs=&quot;0&quot;/> <xsd:element ref=&quot;my:ZipCode&quot; minOccurs=&quot;0&quot;/> </xsd:sequence> <xsd:anyAttribute processContents=&quot;lax&quot; namespace=&quot;http://www.w3.org/XML/1998/namespace&quot;/> </xsd:complexType> </xsd:element> <xsd:element name=&quot;CustomerID&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;CustomerName&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;Address&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;City&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;State&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;ZipCode&quot; type=&quot;xsd:string&quot;/> </xsd:schema> </li>  Add a <Country> element to the schema. The modified Myschema.xsd file appears as follows: <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?> <xsd:schema targetNamespace= &quot;http://schemas.microsoft.com/office/infopath/2003/myXSD/2003-09-16T19:01:29&quot; xmlns:my=&quot;http://schemas.microsoft.com/office/infopath/2003/myXSD/2003-09-16T19:01:29&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;> <xsd:element name=&quot;Customers&quot;> <xsd:complexType> <xsd:sequence> <xsd:element ref=&quot;my:CustomerID&quot; minOccurs=&quot;0&quot;/> <xsd:element ref=&quot;my:CustomerName&quot; minOccurs=&quot;0&quot;/> <xsd:element ref=&quot;my:Address&quot; minOccurs=&quot;0&quot;/> <xsd:element ref=&quot;my:City&quot; minOccurs=&quot;0&quot;/> <xsd:element ref=&quot;my:State&quot; minOccurs=&quot;0&quot;/> <xsd:element ref=&quot;my:ZipCode&quot; minOccurs=&quot;0&quot;/> <xsd:element ref=&quot;my:Country&quot; minOccurs=&quot;0&quot;/> </xsd:sequence> <xsd:anyAttribute processContents=&quot;lax&quot; namespace=&quot;http://www.w3.org/XML/1998/namespace&quot;/> </xsd:complexType> </xsd:element> <xsd:element name=&quot;CustomerID&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;CustomerName&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;Address&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;City&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;State&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;ZipCode&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;Country&quot; type=&quot;xsd:string&quot;/> </xsd:schema> </li> Save and then close the Myschema.xsd file.</li> Right-click the Manifest.xsf file that is included in the extracted files for the ExtSchema template, and then click Design.

The form opens in Design view in InfoPath.

In the Data Source task pane, notice that the Customers group now contains the Country field.</li> On the File menu, click Save as, type a suitable name in the File name field, and then click Save. This will save the template with the modified schema.

Note InfoPath 2003 Service Pack 1 and later versions of InfoPath add the Convert Main Data Source command to the Tools menu in InfoPath Designer. This command enables you to directly choose a new external schema file for the template.</li></ol>

back to the top

Troubleshooting
When you make manual changes to a schema, this may turn out to be an involved process. When you modify the schema, the changes may work flawlessly for some changes to the schema (such as the addition of an optional element), but the changes may create problems for other changes. When you make any changes to a schema, make sure to thoroughly test your form, especially any areas that were built around the changes to the schema. You must also make a backup of your solution before you make any changes to the schema. You must make this backup in case the changes to the schema break the solution.

Important If you design your form from an external schema to be compatible with an existing data source, these changes have the potential to break this compatibility. InfoPath does not perform any checks to make sure that the documents that are generated from the form are still valid against the original schema. However, the documents that are generated from the form are valid against the modified schema that you create.

Additionally, you must be aware that you may also have to modify the Template.xml file, the View.xsl file, the Manifest.xsf file, the Sampledata.xml file, and the scripts of your solution if you make incompatible changes to the schema.

It is a good practice to set up the schema to be extended before you design the form. Forms that are created from a database or from a Web service support this automatically. While you cannot modify the <queryFields> group and the <dataFields> group of these forms because InfoPath uses these fields when it interacts with the data source, you can add additional attributes and additional elements to the <myFields> element to extend the data that is stored in the form.

To extend the data that is stored in the form in an XML schema file (.xsd), add the <xsd:any> child element and the <xsd:anyAttribute> child element to those elements of the schema that can withstand modification in InfoPath. These are elements that can withstand modification without breaking integrity with other applications that use data with the schema. The following code shows an example of how to add the <xsd:any> child element and the <xsd:anyAttribute> child element to those elements of the schema that can withstand modification: <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?> <xsd:schema targetNamespace=&quot;http://www.contoso.com/sampleSchema&quot; xmlns:my=&quot;http://www.contoso.com/sampleSchema&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;>

<xsd:element name=&quot;myFields&quot;> <xsd:complexType> <xsd:sequence> <xsd:element ref=&quot;my:field1&quot; minOccurs=&quot;0&quot;/> <xsd:any namespace=&quot;##other&quot; processContents=&quot;lax&quot; minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot;/> </xsd:sequence> <xsd:anyAttribute namespace=&quot;##other&quot; processContents=&quot;lax&quot;/> </xsd:complexType> </xsd:element> <xsd:element name=&quot;field1&quot; type=&quot;xsd:string&quot; /> </xsd:schema> In this schema, the element cannot be modified in InfoPath. However, Form Designer can add additional elements. The additional elements are indicated by the <xsd:any> node and by the <xsd:anyAttribute> node in the <myFields> element. InfoPath uses a new namespace to avoid the risk of naming conflicts when it adds new elements and new attributes to an existing schema. The following attribute in the schema indicates that this is permitted: namespace=&quot;##other&quot; back to the top

Additional query words: IP2007

Keywords: kbhowto KB827006

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.