How InfoPath Uses XML


You must be asking “What does this have to do with InfoPath?” If you were to skip ahead to the next chapter, which looks at filling out InfoPath forms, you would discover that when you fill out and save a form within InfoPath, the data can either be saved within an XML file or submitted to a back-end database or web service. And when working with a form, there is an XML schema behind the scenes that describes what values are acceptable to the form and are used for validating data.

When you are developing InfoPath forms, you can also use XML files and schemas as data sources. And when you save your form, the form definition file (which has an .xsf extension) is saved using XML, with a number of other supporting files that make up your form template.

The following sections look at all of these different uses of XML in detail, starting with using an XML file as the data source for your form.

XML Data Sources

When you are creating a form to collect information from a user, you have a number of different ways to get started, one of the easiest of which is to use an existing XML file as the data source for your form. Since XML is “self-describing” (meaning that the definition of the field is contained within the file itself) it is the perfect file format to use when creating a form template.

Note

You can also create forms based on other data sources, including Microsoft SQL Server and Microsoft Access databases, web services, and so on. These methods are covered in detail in Chapter 5, which describes how to work with data sources.

Why would you use an XML file as a starting point for your form? To begin with, you may have an existing XML file or schema that you want to use. InfoPath can connect directly to Microsoft SQL Server or Access databases and web services to “push” form data back into a database. But if you are working with another database format, XML also makes it easy to exchange information.

For example, suppose that your organization uses a General Ledger application that runs on Oracle and you need to create a form to collect expense-related information. Your Oracle database administrator (DBA) could provide you with an XML file that matches the information that needs to be entered. You could then use this XML file as the data source for your form, ensuring that any data you collect with your form could be correctly imported into Oracle.

Most databases or applications released in the past few years can generate XML files, and there are many third-party tools available to transform data from various formats to XML. If you do have some experience with XML, you can create your own XML file as a starting point for your form—just make sure that it is a valid XML file before you start; otherwise, you may run into problems! If you aren’t that handy with XML, you can create your data source on-the-fly by simply working with a blank form—as you add data entry controls, text boxes, and so forth, InfoPath will build the data source for you.

Form Templates

When you create your first form, you’ll save the form to an XSN file format, which is unique to InfoPath. If you were to look at the structure of an XSN file, you would see that it is actually a compressed CAB file consisting of a number of other files that make up an InfoPath form, as shown in Figure 2-3.

Note

CAB files are compressed files that are used to distribute software applications and data, similar to Zip files.

As you design forms like this one, InfoPath is creating all of these underlying files behind the scenes to correspond to different parts of your form’s design, and all of these files are based on XML.

The filenames shown in the diagram in Figure 2-3 are from one of the sample invoice forms that ship with InfoPath. To see all the files that make up this InfoPath form, you can open the Invoice (Single Tax Rate) form in design mode (which is introduced in Chapter 4) and then select File | Extract Form Files.

Note

A number of other types of files can make up a form template, but this chapter is concentrating on XML, so the other files aren’t shown in this diagram.

The following sections look at the different types of XML files that are used in an InfoPath form, as well as what each type is used for, using the Invoice form as an example.

XML Schema

An XML schema file is used to describe the form definition file (which has an .xsf extension) and also provides the structure for the XML that will be generated when the user fills out and saves the form. In the example Invoice form, the XML schema describes all the fields that you would normally find on an invoice and includes information about the type of field, length, and so on. In addition to the other uses previously listed, this information is also used for simple form validation (you wouldn’t be able to enter text into a field marked as numeric, for example).

Form Definition File

A form definition file (.xsf file extension) describes the form and layout, identifies any XML schemas that are in use, and contains information about other files related to the form and deployment settings. Form definition files are automatically created by InfoPath when you are working with the design of your form, and may contain information about how the form is deployed as well.

In the example Invoice form, this file is named manifest.xsf, which is a fairly accurate description of its function—it is a manifest of all the related files and includes information about how the form is deployed and the processing instructions that will be carried out when the form is saved or submitted.

XML Sample Data

When you are designing forms, another key area where XML is used is sample data. Often, forms do not make sense to users until they see some data entered into the form—sample data can be used to demonstrate what values should be entered into a particular field or section. In the example Invoice form, the sample.xml file is used to store sample values that may appear on the form.

Form Views

Another use of XML technology within InfoPath can be found in form views. A view within a form is used to organize form data. A form can have multiple views to display different controls or data entry objects. An easy way to think of views is to imagine your form as a multipage document—each one of those pages is a view. InfoPath uses a standard Extensible Stylesheet Language Transformations (XSLT) form to describe these views. The example Invoice form has a single default view; if you were to look in the associated XSL file, you would see all the formatting for this view, including fonts, colors, and other items.

start sidebar
Did You Know?—InfoPath Supports XPath

To create expressions or simple calculations within a form, InfoPath supports XPath, which is a language that was designed to reference parts of an XML document. In addition to enabling you to precisely reference part of an XML document, XPath also provides a number of operators and functions that you can use to perform simple arithmetic calculations, summaries, string manipulations, and more.

Note

For more information about creating XPath expressions, check out Chapter 7.

end sidebar

Form Data Files

With all of that XML technology behind the scenes, it is no wonder that the file format for any forms that you fill out is XML. In the next chapter, you will look at the most basic type of InfoPath implementation, where a form is created and used to save the results to an XML file. You can then use this file to import data into other applications or systems, and InfoPath provides the capability to merge multiple form data files into a single file for further analysis or use.




How to Do Everything with Microsoft Office InfoPath 2003
How to Do Everything with Microsoft Office InfoPath 2003 (How to Do Everything)
ISBN: 0072231270
EAN: 2147483647
Year: 2006
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net