Alternatives to XForms


Although XForms is a W3C standard, some forms packages have obviously been available for many years. With the advent of XML, many of these packages began to use XML to define the form layout. In addition, while XForms worked its way through the standards bodies, other competing XML formats were defined. The most notable of these is Microsoft InfoPath, but other similar designers include Adobe LifeCycle Designer.

Microsoft InfoPath

InfoPath is the member of the Office family used to create XML forms. It is positioned primarily as a Web Service and SharePoint client, but it can also be used standalone to create XML files. InfoPath uses a similar model to XForms to define its forms (see Figure 23-21). There is a model, a user interface, and a submission mechanism. In the case of InfoPath, the model is the XML Schema or WSDL definition of a block of XML or Web Service. Alternatively, a SQL Server or Microsoft Access database can be used, and the schema is derived from the table structure. The user interface is created using the InfoPath tool (see Figure 23-22). The submission mechanism is typically a Web Service, although you can also use InfoPath to save XML files.

image from book
Figure 23-21

image from book
Figure 23-22

As you can see from the architecture diagram, XSLT is used to create the user interface. The InfoPath file includes this XSLT, as well as any associated XSD or XML files and a manifest file. These are stored in one file using the ZIP file format, although the extension is XSN.

The InfoPath designer enables the creation of form-based solutions using a drag-and-drop model. You can drag elements or groups of elements from the right sidebar over to the design surface. The designer chooses a control based on the data type; however, this can be overridden if necessary. The available controls include a number of layout options, such as table and freeform layouts. You can also add additional secondary data sources to populate portions of the form.

The programming of an InfoPath form can take one of at least three forms. First, it supports a declarative model for applying rules and formatting based on the data. These rules typically take the form of XPath expressions. InfoPath includes designers to assist in the creation of these expressions, so that most users do not need to know XPath to create them (see Figure 23-23). Although this scenario is fine for most simple cases, InfoPath also provides a more programmatic approach using JavaScript. Using this model, you attach JavaScript functions to events or objects in the designer. Finally, through the addition of the InfoPath Toolkit for Visual Studio, you can integrate InfoPath development with Visual Studio .NET 2003, or Visual Studio 2005 to use C#, Visual Basic, and the .NET Framework to extend your InfoPath forms.

image from book
Figure 23-23

Figure 23-24 shows an InfoPath form that uses the same ExpenseReport schema used in the earlier example.

image from book
Figure 23-24

As with the earlier XForms example, the fields are bound to the data in the model. The central table enables the user to add multiple expense items. The drop-down lists for the department and type are populated from the XML as well. The department list comes from the secondary departments.xml file, whereas the expense type list is populated from the values of the enumeration in the schema. Some validation is preformed automatically based on the data types in the schema, and required fields are marked in the editor.

As described previously, fields can also be populated dynamically, either through code or XPath expressions. As with XForms, these expressions update as the data changes. The four summary fields are populated based on the expense items entered using an XPath expression like the following.

      sum(amount[type = "Travel"]) 

As the underlying XML changes, this XPath expression is reapplied. This ensures that the summary totals for each category are updated on any change. You can confirm this by changing the type or amount of each expense item. The resulting XML is shown in Listing 23-16.

Listing 23-16: XML produced by InfoPath

image from book
      <?xml version="1.0" encoding="utf-8"?>      <?mso-infoPathSolution solutionVersion="1.0.0.6"        productVersion="11.0.6565" PIVersion="1.0.0.0"        href="http://server/ExpenseReport.xsn"        name="urn:schemas-microsoft-com:office:infopath:Expense-Report:http---example-      com-expenseReport" language="en-us" ?>      <?mso-application prog?>      <exp:expenseReport xmlns:exp="http://example.com/expenseReport"      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"      xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-07-19T04:04:      02"      xmlns:ns1="http://example.com/depts">        <exp:employee>          <exp:name>Foo deBar</exp:name>          <exp:employeeID>42</exp:employeeID>          <exp:dept>dev</exp:dept>        </exp:employee>        <exp:date>2006-04-01</exp:date>        <exp:purpose>Conference trip</exp:purpose>        <exp:startDate>2006-03-26</exp:startDate>        <exp:endDate>2006-04-01</exp:endDate>        <exp:expenseItem>          <exp:date>2006-03-27</exp:date>          <exp:type>Travel</exp:type>          <exp:amount>365.34</exp:amount>          <exp:description>Airfare</exp:description>        </exp:expenseItem>        <exp:expenseItem>          <exp:date>2006-03-27</exp:date>          <exp:type>Meal</exp:type>          <exp:amount>23.40</exp:amount>          <exp:description>Meal at destination</exp:description>        </exp:expenseItem>        <exp:expenseItem>          <exp:date>2006-03-28</exp:date>          <exp:type>Meal</exp:type>          <exp:amount>5.00</exp:amount>          <exp:description>Meal</exp:description>        </exp:expenseItem>        <exp:expenseItem>          <exp:date>2006-03-28</exp:date>          <exp:type>Miscellaneous</exp:type>          <exp:amount>50</exp:amount>          <exp:description>Replacement power cable</exp:description>        </exp:expenseItem>        <exp:expenseItem>          <exp:date>2006-03-28</exp:date>          <exp:type>Entertainment</exp:type>          <exp:amount>250</exp:amount>          <exp:description>Meal with customers from Gizmos R          Them</exp:description>        </exp:expenseItem>        <exp:summary>          <exp:travelSummary>365.34</exp:travelSummary>          <exp:entSummary>250</exp:entSummary>          <exp:mealSummary>28.4</exp:mealSummary>          <exp:miscSummary>50</exp:miscSummary>        </exp:summary>      </exp:expenseReport> 
image from book

Comparing XForms and InfoPath

Because they are the two leading choices for creating XML-based forms, it's worth comparing XForms with InfoPath. Functionally, they are similar, but they differ in support levels and functionality (see the following table).

Open table as spreadsheet

Feature

Xforms

InfoPath

Standardization

W3C standard

Proprietary

Programmability

Declarative (XPath)

Declarative (XPath) JavaScript .NET Framework (with the InfoPath Toolkit for Visual Studio .NET 2003)

Browser support

Any (with an appropriate plug-in)

None (although InfoPath 2007 supports running in any browser)

Designer support

Available

Built-in

Event-driven programming model

Yes

Yes

Data Model

Inline model W3C Schema

W3C Schema WSDL SQL Server/Access

Output

XML x-www-urlencoded other based on implementation

XML SOAP

XPath support

1.0

1.0

Like most other decisions concerning software, the decision may already be made for you. Either company standards or policy may point you at either a proprietary solution or to a more standards-based solution.




Professional XML
Professional XML (Programmer to Programmer)
ISBN: 0471777773
EAN: 2147483647
Year: 2004
Pages: 215

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