How to modify an external schema for an InfoPath form (827006)



The information in this article applies to:

  • Microsoft Office InfoPath 2003

SUMMARY

When you design a form that is based on an external schema, 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

  1. Start InfoPath. Create a new blank form.
  2. To design the schema, follow these steps:
    1. In the Data Source task pane, right-click myFields, and then click Properties.
    2. In the Field or Group Properties dialog box, change the name from myFields to Customers, and then click OK.
    3. Right-click Customers, and then click Add.
    4. In the Add Field or Group dialog box, set the Name property to CustomerID, and then click OK.
    5. 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.
  3. Save the template as Schema1.xsn.
  4. On the File menu, click Extract Form Files, and then select a location to save the extracted files to.
  5. Close Schema1, but do not exit InfoPath.
back to the top

Create an InfoPath Form That Is Based on an External Schema

  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.
  3. Select XML Schema or XML data file, and then click Next.
  4. 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.
  5. 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.
  6. Save this template as ExtSchema.xsn.
back to the top

Modify the Schema

  1. Make sure that the ExtSchema template is open in InfoPath. On the File menu, click Extract Form Files to extract the files.
  2. Exit InfoPath.
  3. 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="1.0" encoding="UTF-8" standalone="no"?>
    <xsd:schema targetNamespace=
    "http://schemas.microsoft.com/office/infopath/2003/myXSD/2003-09-16T19:01:29" 
    xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2003-09-16T19:01:29" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    	<xsd:element name="Customers">
    		<xsd:complexType>
    			<xsd:sequence>
    				<xsd:element ref="my:CustomerID" minOccurs="0"/>
    				<xsd:element ref="my:CustomerName" minOccurs="0"/>
    				<xsd:element ref="my:Address" minOccurs="0"/>
    				<xsd:element ref="my:City" minOccurs="0"/>
    				<xsd:element ref="my:State" minOccurs="0"/>
    				<xsd:element ref="my:ZipCode" minOccurs="0"/>
    			</xsd:sequence>
    			<xsd:anyAttribute processContents="lax" namespace="http://www.w3.org/XML/1998/namespace"/>
    		</xsd:complexType>
    	</xsd:element>
    	<xsd:element name="CustomerID" type="xsd:string"/>
    	<xsd:element name="CustomerName" type="xsd:string"/>
    	<xsd:element name="Address" type="xsd:string"/>
    	<xsd:element name="City" type="xsd:string"/>
    	<xsd:element name="State" type="xsd:string"/>
    	<xsd:element name="ZipCode" type="xsd:string"/>
    </xsd:schema>
  4. Add a <Country> element to the schema. The modified Myschema.xsd file appears as follows:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <xsd:schema targetNamespace=
    "http://schemas.microsoft.com/office/infopath/2003/myXSD/2003-09-16T19:01:29" 
    xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2003-09-16T19:01:29" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    	<xsd:element name="Customers">
    		<xsd:complexType>
    			<xsd:sequence>
    				<xsd:element ref="my:CustomerID" minOccurs="0"/>
    				<xsd:element ref="my:CustomerName" minOccurs="0"/>
    				<xsd:element ref="my:Address" minOccurs="0"/>
    				<xsd:element ref="my:City" minOccurs="0"/>
    				<xsd:element ref="my:State" minOccurs="0"/>
    				<xsd:element ref="my:ZipCode" minOccurs="0"/>
    				<xsd:element ref="my:Country" minOccurs="0"/>
    			</xsd:sequence>
    			<xsd:anyAttribute processContents="lax" namespace="http://www.w3.org/XML/1998/namespace"/>
    		</xsd:complexType>
    	</xsd:element>
    	<xsd:element name="CustomerID" type="xsd:string"/>
    	<xsd:element name="CustomerName" type="xsd:string"/>
    	<xsd:element name="Address" type="xsd:string"/>
    	<xsd:element name="City" type="xsd:string"/>
    	<xsd:element name="State" type="xsd:string"/>
    	<xsd:element name="ZipCode" type="xsd:string"/>
    	<xsd:element name="Country" type="xsd:string"/>
    </xsd:schema>
  5. Save and then close the Myschema.xsd file.
  6. Right-click the Manifest.xsf file that is in the extracted files for the ExtSchema template, and then click Design.

    This opens the form in Design view in InfoPath.

    In the Data Source task pane, notice that the Customers group now contains the Country field.
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="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema targetNamespace="http://www.contoso.com/sampleSchema" 
xmlns:my="http://www.contoso.com/sampleSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

   <xsd:element name="myFields">
      <xsd:complexType>
         <xsd:sequence>
            <xsd:element ref="my:field1" minOccurs="0"/>
           <xsd:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
         </xsd:sequence>
         <xsd:anyAttribute namespace="##other" processContents="lax"/>
      </xsd:complexType>
   </xsd:element>
 
   <xsd:element name="field1" type="xsd:string" />
</xsd:schema>
In this schema, the <field1> 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="##other"
back to the top

Modification Type:MinorLast Reviewed:10/21/2004
Keywords:kbhowto KB827006 kbAudDeveloper