Viewing and Publishing Forms as HTML


Another easy method you can use to publish or distribute form data is to export it to HTML. There are two different methods you can use to publish your form, depending on your requirements. If you want to export a form to HTML from within InfoPath, there is a simple export process that you can use from the File menu to export your form, which can then be viewed in a web browser, posted to a web site, and so on.

If you need to convert a large number of forms or if you are sending the form to a user who does not have InfoPath and may need to view the form, there is also a “downlevel” tool provided in the InfoPath SDK (Software Development Kit) that can be used to convert the form so that it can be viewed using your web browser.

The following sections examine both of these methods and describe how they can be used with your forms, starting with the export method.

Exporting a Form to HTML

In order to export a form to HTML, you need to have an InfoPath form that has been filled out, like the one shown in Figure 14-3.

click to expand
Figure 14-3: A typical InfoPath form

To export your form from within InfoPath, open the Form View you would like to export and select File | Export To | Web. This opens a standard Save As dialog box that enables you to enter a filename and location for your exported form. When you are finished, click OK to export your form.

You’ll notice that when InfoPath exports your form and data, it doesn’t use a standard HTML file format. The file format that InfoPath uses instead is MHT, which is an abbreviation for MHTML (MIME Encapsulation of Aggregate HTML Documents). MHTML is an Internet standard that was originally defined as a method of sending complete web pages in the body of an e-mail message. Since this file format was introduced, it has been adapted for a variety of other uses, such as to archive web pages and publish HTML documents using a single file structure.

Tip

In fact, from any Microsoft Office application, you can select File | Save As to save the document as an MHT file.

An MHTML file can contain multiple web pages and all the required images, scripts, and other external files that are required to make the pages appear as normal. Once you have exported your form to this format, you can then open it using your web browser, as shown in Figure 14-4.

click to expand
Figure 14-4: An exported form

You can also open an MHT file in any application that supports opening and editing MHT files, including Microsoft Word. The following are a few points to remember when working with the MHT file that InfoPath generates:

  • Your exported form is static, so if you update the form data and want to update your web pages, you need to go through the export process again.

  • If you choose to edit the MHT file, the form design may not be as precise as the design you created on the form. Since MHT files are made up of HTML files, and different editors handle HTML in different ways, you may end up with mixed results.

Using the Downlevel Tool

If you need to convert a large number of forms to HTML or if you do not have InfoPath installed, you may want to consider using the “downlevel” tool provided in the InfoPath SDK to take an InfoPath form and generate a downlevel view that can be viewed through a standard web browser.

Tip

If you haven’t done so already, you need to download and install the InfoPath SDK to perform the tasks listed in this section. You can find a link to the SDK and related documentation from the main InfoPath web site at www.microsoft .com/infopath.

The downlevel tool is a command-line utility that you can use to convert a single form or to write batch scripts to convert large numbers of forms. The good news is that you don’t need to have InfoPath installed to use the utility, so it is a good solution for users who may need to view forms but don’t have InfoPath installed locally.

The utility creates this downlevel view by creating a style sheet that is used to display the form in a web browser. This style sheet is similar to the style sheets that you looked at in Chapter 2 that are used to define InfoPath views, but this style sheet has been created specifically for viewing the form in a web browser.

To use the downlevel tool, you need to have the InfoPath SDK installed. By default, the tool is located in C:\Program Files\Microsoft Office 2003 Developer Resources\Microsoft Office InfoPath 2003 SDK\Tools\XDown\ (although you may want to move the xdown.exe file to a more convenient location).

Creating a Downlevel View of a Form Template

The first use of the downlevel tool that you’ll look at is to create a downlevel style sheet for a form template (XSN), which will allow users to view the structure of the form template using a standard web browser.

To use the downlevel tool, you need to pass a number of command-line switches, including the name of the form template, as well as a destination for the transformed files. Suppose that you have a form like the one shown in Figure 14-5, named invoice.xsn, and you want to create a downlevel style sheet and place all the required files in a directory called C:\Myforms\. The command line might look something like this:

XDown /d invoice.xsn c:\myforms\

click to expand
Figure 14-5: A sample invoice form

The /d switch is required whenever you use the utility. It indicates that you want to create a downlevel view—the source form and target location follow afterwards.

Note

If you are using the downlevel utility on a computer that has InfoPath already installed, you also need to add the /C switch at the end of the command line. Otherwise, when you go to look at the downlevel form, it will be opened in InfoPath instead of your web browser.

If you were to look in the C:\Myforms\ directory, you would see that the downlevel utility actually separated the InfoPath form into its component files and that you can now view the form by viewing the template.xml file that was generated. Your form should appear something like the form shown in Figure 14-6.

click to expand
Figure 14-6: A downlevel view of the form

Tip

If you open your form and an application other than Internet Explorer or Netscape opens, you may need to change your file associations, because another application has the XML file format associated with it. Alternately, you could also open this file from within your web browser.

Creating a Downlevel View of a Form with Data

Once you have created the downlevel style sheet for your form template, you can then use that style sheet to view InfoPath forms you have filled out. This will enable users to see the XML data file in the form itself without having InfoPath installed on their computer.

First, locate the style sheet that was created in the previous step—it will have an .xsl extension and will be located in the same directory as the other expanded files. Next, you need to locate the XML file that was created when you saved your form after filling it out. From the example in this chapter, the Invoice form we have been working with has been filled out and saved as invoice20390.xml.

If you were to view this file as it is in Internet Explorer or a web development tool like Dreamweaver, it would look something like the screen shot shown in Figure 14-7 (not very pretty!).

click to expand
Figure 14-7: An XML file viewed in Dreamweaver

To apply the downlevel style sheet to this XML file, you need to edit the XML file itself. You can edit this file in Notepad if you like, or if you use a special XML tool (like XMLSpy) or web editor (FrontPage, Dreamweaver, and so on), you can use these tools as well; just make sure that you save the file back with an .xml extension. At the start of your XML file will be a section marked:

<?xml version="1.0" encoding="UTF-8"?>

Immediately after this section, you want to add a reference that tells your XML file to use the downlevel style sheet that was created earlier from your form template. To do so, insert the following element immediately after the preceding text:

<?xml-stylesheet type="text/xsl" href="default.xsl"?>

Remember to substitute the name and location of the style sheet you have generated earlier—in this example, the style sheet is just called default.xsl. If you want to view this XML file in your web browser on a computer that already has InfoPath installed, you need to do a little further editing.

On the same line of text, locate and delete the following—this will “break” the association with InfoPath so that you can view the XML file in Internet Explorer, instead of opening the form in InfoPath:

<?mso-application prog?>
<?mso-infoPathSolution solutionVersion="1.0.0.3" productVersion="11.0.5531" PIVersion="1.0.0.0" href="file:///C:\xdown\invoice.xsn" ?>

You should now be able to open the form within Internet Explorer and it should look similar to the original form and display the form data in all the correct places.

Working with Views

By default, when you are working with the downlevel tool, it creates a downlevel style sheet that allows you to view the form’s default view. But forms can have many views and often there will be a print version of a view that you may want to display. By using the command-line switches provided with the downlevel utility, you can retrieve a list of the views in use within a form and then alter the XML file to use a downlevel style sheet created from this view.

To list all the views that are present within a form, you can use the /l switch, as shown in the following command line:

Xdown /l invoice.xsn

start sidebar
How to...—Update Downlevel Files

If you change your form template file, you may also need to update the style sheet and other files that are generated through the downlevel tool. The easiest way to do that is to use the tool's update flag to update the required files. But before you decide to update the files, it is always a good idea to look at which files would be updated or changed in the process. The downlevel utility provides the functionality through the /f switch, so to list all the files that would be changed, use the following command line:

end sidebar

XDown /d invoice.xsn c:\myforms\ /f

This produces a list of files that tells you which files are going to be changed or updated. You can then decide if you want to proceed with the update—if you decide to proceed, you can update these files using the /! switch. So, from the earlier example if the Invoice form had been changed, you would need to use the following command line to update all the related form files:

XDown /d invoice.xsn c:\myforms\ /!

This switch should enable you to integrate the output from the utility with other applications and systems—by updating the files instead of writing new filenames or other schemes, you can ensure that any processes or applications you hang off of these files won't be broken when you update the form template.

You don’t need to specify a destination directory when using the switch, because you are not actually doing any transformations at this point—you are only getting a list of views that appear in the form, so the contents of the list depends on the views that are present in the form you are working with.

Once you have identified the name of the view, you can then use either the view name or the XSL filename with the /t switch to transform your XML file to include this style sheet. So, following through on the example used previously in this chapter, the Invoice form has a view called Print that has an associated style sheet named print.xsl. To create a downlevel style sheet from this view, the command line would look like this:

XDown /d invoice.xsn c:\myforms\ /t:print.xsl

This would place the reference to the style sheet in your XML file, so that when you later view the file, the downlevel style sheet for this view would be used, displaying the preferred print view used in your form.

Note

Be careful when specifying different views, because the view that you select may not have the same fields, which will cause an error when you try to view the form using an incompatible style sheet.

Additional Command-Line Options

As you have been using the downlevel tool, you may have noticed that it generates a lot of status messages while it is running. If you have a large number of templates to convert or if you are running this utility as part of a script or batch process, you may want to hide this commentary. The /v switch can be used to control how verbose the utility is when running. You can specify a value from 0 to 4, which ranges from no comments at all (0) to becoming a chatterbox. So, if you want to create a downlevel style sheet with no comments at all, your command line would look something like this:

XDown /d invoice.xsn c:\myforms\ /v:0

You may have also noticed that when the downlevel utility runs, it expands your XSN file and copies all the internal files to the destination directory you specified. This is the equivalent of using the Extract Form Files option within InfoPath, for one exception—the scripting files are not copied with the other form files. You can use the /a switch to copy all the form files, including any scripting files, to your destination directory. To copy all the form files using the first example with the Invoice form, the command line would look something like this:

XDown /d invoice.xsn c:\myforms\ /v:0




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