Chapter 2: Form Template Architecture
This chapter provides an overview of the architecture of an InfoPath form template and gives you insight into the purpose of the various form files that may be combined in a template to meet business requirements. Here, you’ll crack open your first template file and examine an annotated form definition file, along with a related XML instance.You’ll learn how XML schemas are associated with InfoPath depending on the data source that you choose. Then, as a prelude to the following chapter, you’ll review some of the basic elements and attributes of XML Schema and look at the schema diagram conventions we use throughout the book.
Package Structure
When you open a template in InfoPath, the interface displays a single template file. This is a compressed file format that packages all the form files into one file. To quickly see how a package is made up, open any of the samples that come with InfoPath in design mode. Choose File→ Extract Form Files, and save them to a convenient folder. What you see in the extract folder will vary with the file you have selected. When designing a form, you can work with these individual form files. For example, you can make manual changes to the form definition file or edit the XML schema. One reason you might need to make such a change is that it is the only available method. Also, if you are working with a form based on an existing schema, you must modify it outside of InfoPath with a text or XML editor.InfoPath templates can vary in complexity, depending on the requirement they are addressing, so you won’t necessarily need to use all these file types in a given application.
Form Template
The form template is the compressed file format that packages all the form files into one file. If you’ve extracted some form files from the compressed format as suggested, you can use any text or XML editor to examine them. The file extension is .xsn.
Form Definition
A form definition file is automatically generated by InfoPath when a new template is created and saved in design mode. It contains information about the form as a whole, together with all of the other files and components used in a form. As its name implies, the file serves as the manifest for the template. As you modify the template or add new features to it, InfoPath updates the manifest. The file extension is .xsf.You can also modify this file directly. Indeed, there are several features that you can’t add to the form definition file, such as custom toolbars, in design mode. However, you should take care in making changes, as you might leave the form template in an unusable state.Because it is so central to form architecture, we’ve devoted Chapters 3 and 4 to a more detailed analysis of structure of the XSF file. The full XSF schema and a complete InfoPath XSF Reference are contained in Appendixes A and B.
XML Schema
The XML Schema files, referred to in a form’s XML data file and that define its structure, are listed in the form definition. For simple forms you’ll probably only want to reference a single schema document, but InfoPath supports multiple schemas if you need to use elements from more than one namespace. The file extension is .xsd.If you use a modular schema and refer to modules using the xsd:include or xsd:import XML Schema elements, these module files also need to be included in the template. However, only the main schema file should be listed in the form definition.
View
InfoPath supports multiple views of form data. The view files contain the XSLT style sheets that InfoPath uses to build the primary user interface from the underlying XML data file. Each view listed in the form definition contains a reference to the related transform. The file extension is .xsl.
XML Template
The XML template file contains any default data that is displayed in a view when a new form is created by a user. This is just one way of providing default information. You can, for example, create scripts that automate the production of default values. The file extension is .xml.
XML Component Template
The component template contains XML representations of the editing controls that are used when creating and filling out a form. The file extension is .xct.
Presentation
This category includes the files used in conjunction with a view to create a custom user interface. Examples include HTML and image data files, and CSS style sheets.
Business Logic
Any JavaScript, JScript, or VBScript files used to program editing behaviors, data validation, event handlers, and other logic are contained in a scripts section of the form definition. Multiple script files are supported.InfoPath combines all the listed files into a single scripting environment. Therefore, you should use only one of the supported languages in all the scripts for a form and ensure that script files have unique names and that there will be no name clashes in identifiers.
Binary Data
You can also include custom Component Object Model (COM) components to provide additional business logic.
Repackaging a Template
Often you can design a form without recourse to editing the individual files, because InfoPath will make a wide range of changes in the background, depending on what you choose to modify and the nature of the form’s data source.Our purpose in getting you to extract the form files in this chapter is to let you see the overall makeup of a template and get an overview of the structure of a form definition file. Extracting the form file leaves the original template intact, so you won’t need to rebuild the files you’ve been examining.However, if you have occasion to modify any of the form files belonging to a template, you can repackage the template by simply right-clicking the XSF file and choosing Design to open it. Then, choose Save As from the File menu, and click the Save button to save the template.You’ll read more about modifying form files throughout the book, and you can follow a detailed discussion of upgrading and related issues in Chapter 9.