Form Definition Example
Following is an annotated example of a form definition file to give you an initial impression of XSF structure and content and to help you relate that to the form schema and instance. The XSF file is also from uibasic.xsn. The usual path of the sample files is c:\program files\microsoft office\office11\ samples\infopath\. To follow the examples, from Windows Explorer, you should open the form in design mode by right-clicking the file and choosing Design.
The User Interface sample form allows you to enter the artist, title, track names, and optionally the label of items in a collection of CDs. A custom task pane contains buttons that switch views, sorts the listing, and imports selected CDs from an XML file. Figure 2-2 shows the form interface.
Figure 2-2: Part of the User Interface sample form in design mode.
First, here’s the XML schema for the form:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="CustomUISample">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="CDCollection"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"
namespace="http://www.w3.org/XML/1998/namespace"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="CDCollection">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="CD" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="CD">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Title"/>
<xsd:element ref="Artist"/>
<xsd:element ref="Tracks"/>
<xsd:element ref="Label" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Title" type="xsd:string"/>
<xsd:element name="Artist" type="xsd:string"/>
<xsd:element name="Tracks">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Track" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Track" type="xsd:string"/>
<xsd:element name="Label">
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:any minOccurs="0" maxOccurs="unbounded"
namespace="http://www.w3.org/1999/xhtml" processContents="lax"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
An XML instance, also in the samples folder, is named cdlist.xml. This file is intended to be used as an example to import. You can also view it in design mode by choosing File→Preview Form→With Data File. It looks like this:
<?xml version="1.0" encoding="utf-8"?>
<CustomUISample>
<CDCollection>
<CD>
<Title>Meisner Darrell</Title>
<Artist>Meisner Darrell</Artist>
<Tracks>
<Track>When The Saints Go Marching In</Track>
<Track>On The Sunny Side Of The Street</Track>
<Track>Ain’t Misbehavin’</Track>
</Tracks>
<Label></Label>
</CD>
<CD>
<Title>Abbas Syed</Title>
<Artist>Abbas Syed</Artist>
<Tracks>
<Track>Dreams</Track>
<Track>5150</Track>
</Tracks>
</CD>
.
.
<CD>
<Title>Zimmerman Marc</Title>
<Artist>Zimmerman Marc</Artist>
<Tracks>
<Track>via Medina</Track>
<Track>Evviva ‘o Rre’</Track>
<Track>Tempo di cambiare</Track>
</Tracks>
<Label>Proseware Inc.</Label>
</CD>
</CDCollection>
</CustomUISample>
Finally, here’s the form definition file generated by InfoPath, with some annotations:
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is automatically created and modified by Microsoft Office InfoPath.
-->
<!--Top level element with namespace declarations-->
<xsf:xDocumentClass
solutionVersion="1.0.0.2"
productVersion="11.0.5531"
solutionFormatVersion="1.0.0.0" xmlns:xsf="http:
//schemas.microsoft.com/office/infopath/2003/
solutionDefinition" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:xd="http://schemas.microsoft.com
/office/infopath/2003" xmlns:xsi="http://www.w3.org/2001
/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999
/xhtml">
<!--Files in the package and their properties
detailed-->
<xsf:package>
<xsf:files>
<xsf:file name="schema.xsd">
<xsf:fileProperties>
<xsf:property name="editability" type="string"
value="none"></xsf:property>
<xsf:property name="rootElement" type="string"
value="CustomUISample"></xsf:property>
</xsf:fileProperties>
</xsf:file>
<xsf:file name="template.xml"></xsf:file>
<xsf:file name="sampledata.xml">
<xsf:fileProperties>
<xsf:property name="fileType" type="string"
value="sampleData"></xsf:property>
</xsf:fileProperties>
</xsf:file>
<xsf:file name="view1.xsl">
<xsf:fileProperties>
<xsf:property name="viewWidth" type="string"
value="542px"></xsf:property>
<xsf:property name="mode" type="string" value="2"></xsf:property>
<xsf:property name="componentId" type="string" value="13">
</xsf:property>
<xsf:property name="lang" type="string" value="1033"></xsf:property>
<xsf:property name="xmlToEditName" type="string"
value="7"></xsf:property>
</xsf:fileProperties>
</xsf:file>
<xsf:file name="AllTracks.xsl">
<xsf:fileProperties>
<xsf:property name="viewWidth" type="string"
value="542px"></xsf:property>
<xsf:property name="componentId" type="string"
value="3"></xsf:property>
<xsf:property name="xmlToEditName" type="string"
value="1"></xsf:property>
<xsf:property name="lang" type="string" value="0"></xsf:property>
</xsf:fileProperties>
</xsf:file>
<xsf:file name="internal.js">
<xsf:fileProperties>
<xsf:property name="scriptType" type="string"
value="internal"></xsf:property>
</xsf:fileProperties>
</xsf:file>
<xsf:file name="Import">
<xsf:fileProperties>
<xsf:property name="fileType" type="string"
value="resource"></xsf:property>
</xsf:fileProperties>
</xsf:file>
<xsf:file name="taskpane">
<xsf:fileProperties>
<xsf:property name="fileType" type="string"
value="resource"></xsf:property>
</xsf:fileProperties>
</xsf:file>
<xsf:file name="taskpane.css">
<xsf:fileProperties>
<xsf:property name="fileType" type="string"
value="resource"></xsf:property>
</xsf:fileProperties>
</xsf:file>
<xsf:file name="script.js">
<xsf:fileProperties>
<xsf:property name="scriptType" type="string"
value="userEvents"></xsf:property>
</xsf:fileProperties>
</xsf:file>
</xsf:files>
</xsf:package>
<!--Form metadata-->
<xsf:importParameters enabled="no"></xsf:importParameters>
<!--Views start here-->
<!--Name, caption and transform for default view-->
<xsf:views default="CD Collection">
<xsf:view name="CD Collection" caption="CD Collection">
<xsf:mainpane transform="view1.xsl"></xsf:mainpane>
<!--Mainpane editing components-->
<xsf:editing>
<!--Repeating CD group-->
<xsf:xmlToEdit name="CD_10" item="/CustomUISample/CDCollection/CD"
container="/CustomUISample">
<xsf:editWith caption="CD" xd:autogeneration="template"
component="xCollection">
<xsf:fragmentToInsert>
<xsf:chooseFragment parent="CDCollection">
<CD>
<Title></Title>
<Artist></Artist>
<Tracks>
<Track></Track>
<Track></Track>
</Tracks>
</CD>
</xsf:chooseFragment>
</xsf:fragmentToInsert>
</xsf:editWith>
</xsf:xmlToEdit>
<!--Repeating tracks group-->
<xsf:xmlToEdit name="Track_14"
item="/CustomUISample/CDCollection/CD/Tracks/Track"
container="/CustomUISample/CDCollection/CD">
<xsf:editWith caption="Track" xd:autogeneration="template"
component="xCollection">
<xsf:fragmentToInsert>
<xsf:chooseFragment parent="Tracks">
<Track></Track>
</xsf:chooseFragment>
</xsf:fragmentToInsert>
</xsf:editWith>
</xsf:xmlToEdit>
<!--Optional label with rich text control-->
<xsf:xmlToEdit name="Label_16"
item="/CustomUISample/CDCollection/CD/Label"
container="/CustomUISample/CDCollection/CD">
<xsf:editWith caption="Label" xd:autogeneration="template"
component="xOptional">
<xsf:fragmentToInsert>
<xsf:chooseFragment>
<Label></Label>
</xsf:chooseFragment>
</xsf:fragmentToInsert>
</xsf:editWith>
</xsf:xmlToEdit>
<xsf:xmlToEdit name="Label_4"
item="/CustomUISample/CDCollection/CD/Label">
<xsf:editWith type="rich" autoComplete="no"
component="xField"></xsf:editWith>
</xsf:xmlToEdit>
<!--Artist, track and title-->
<xsf:xmlToEdit name="Artist_5"
item="/CustomUISample/CDCollection/CD/Artist">
<xsf:editWith component="xField" autoComplete="no"></xsf:editWith>
</xsf:xmlToEdit>
<xsf:xmlToEdit name="Track_6"
item="/CustomUISample/CDCollection/CD/Tracks/Track">
<xsf:editWith component="xField" autoComplete="no"></xsf:editWith>
</xsf:xmlToEdit>
<xsf:xmlToEdit name="Title_7"
item="/CustomUISample/CDCollection/CD/Title">
<xsf:editWith component="xField" autoComplete="no"></xsf:editWith>
</xsf:xmlToEdit>
</xsf:editing>
<!--Toolbar with buttons to insert/remove objects-->
<xsf:toolbar caption="CD Collection Toolbar" name="CD Collection Toolbar">
<xsf:button action="xCollection::insert" xmlToEdit="CD_10"
caption="New CD" showIf="always"></xsf:button>
<xsf:button action="xCollection::insert" xmlToEdit="Track_14"
caption="New Track" showIf="always"></xsf:button>
<xsf:button action="xOptional::insert" xmlToEdit="Label_16"
caption="New Label" showIf="always"></xsf:button>
<xsf:menu caption="Remove">
<xsf:button action="xCollection::remove" xmlToEdit="CD_10"
caption="CD" showIf="always"></xsf:button>
<xsf:button action="xCollection::remove" xmlToEdit="Track_14"
caption="Track" showIf="always"></xsf:button>
<xsf:button action="xOptional::remove" xmlToEdit="Label_16"
caption="Label" showIf="always"></xsf:button>
</xsf:menu>
</xsf:toolbar>
<!--Table, Insert and View menu definitions-->
<xsf:menuArea name="msoTableMenu">
<xsf:menu caption="Insert Tracks">
<xsf:button action="xCollection::insertBefore" xmlToEdit="Track_14"
caption="Above" showIf="always"></xsf:button>
<xsf:button action="xCollection::insertAfter" xmlToEdit="Track_14"
caption="Below" showIf="always"></xsf:button>
</xsf:menu>
<xsf:menu caption="Remove Tracks">
<xsf:button action="xCollection::remove" xmlToEdit="Track_14"
caption="Remove Current Row" showIf="always"></xsf:button>
</xsf:menu>
</xsf:menuArea>
<xsf:menuArea name="msoViewMenu">
<xsf:button caption="CD Collection" name="SwitchToView0"></xsf:button>
<xsf:button caption="All Tracks" name="SwitchToView1"></xsf:button>
</xsf:menuArea>
<xsf:menuArea name="msoInsertMenu">
<xsf:menu caption="&Section">
<xsf:button action="xCollection::insert" xmlToEdit="CD_10"
caption="CD" showIf="always"></xsf:button>
<xsf:button action="xCollection::insert" xmlToEdit="Track_14"
caption="Track" showIf="always"></xsf:button>
<xsf:button action="xOptional::insert" xmlToEdit="Label_16"
caption="Label"></xsf:button>
</xsf:menu>
</xsf:menuArea>
<!--Context menu-->
<xsf:menuArea name="msoStructuralEditingContextMenu">
<xsf:button action="xCollection::insertBefore"
xmlToEdit="CD_10" caption="Insert CD above" showIf="immediate"></xsf:button>
<xsf:button action="xCollection::insertBefore"
xmlToEdit="Track_14" caption="Insert Track above" showIf="immediate"></xsf:button>
<xsf:button action="xCollection::insertAfter" xmlToEdit="CD_10"
caption="Insert CD below" showIf="immediate"></xsf:button>
<xsf:button action="xCollection::insertAfter"
xmlToEdit="Track_14" caption="Insert Track below" showIf="immediate"></xsf:button>
<xsf:button action="xCollection::remove"
xmlToEdit="CD_10" caption="Remove CD" showIf="immediate"></xsf:button>
<xsf:button action="xCollection::remove"
xmlToEdit="Track_14" caption="Remove Track" showIf="immediate"></xsf:button>
<xsf:button action="xOptional::remove"
xmlToEdit="Label_16" caption="Remove Label" showIf="immediate"></xsf:button>
<xsf:button action="xCollection::insert"
xmlToEdit="CD_10" caption="Insert CD" showIf="immediate"></xsf:button>
<xsf:button action="xCollection::insert"
xmlToEdit="Track_14" caption="Insert Track" showIf="immediate"></xsf:button>
<xsf:button action="xOptional::insert"
xmlToEdit="Label_16" caption="Insert Label" showIf="immediate"></xsf:button>
</xsf:menuArea>
<!--Print settings-->
<xsf:printSettings orientation="portrait"></xsf:printSettings>
</xsf:view>
<!--All tracks view-->
<xsf:view name="All Tracks" caption="All Tracks">
<xsf:menuArea name="msoViewMenu">
<xsf:button caption="CD Collection" name="SwitchToView0"></xsf:button>
<xsf:button caption="All Tracks" name="SwitchToView1"></xsf:button>
</xsf:menuArea>
<xsf:mainpane transform="AllTracks.xsl"></xsf:mainpane>
</xsf:view>
</xsf:views>
<!--More metadata-->
<xsf:applicationParameters application="InfoPath Design Mode">
<xsf:solutionProperties automaticallyCreateNodes="no"
scriptLanguage="jscript" lastOpenView="view1.xsl"
lastVersionNeedingTransform="1.0.0.0">
</xsf:solutionProperties>
</xsf:applicationParameters>
<!--Schema reference-->
<xsf:documentSchemas>
<xsf:documentSchema rootSchema="yes"
location="schema.xsd">
</xsf:documentSchema>
</xsf:documentSchemas>
<xsf:fileNew>
<xsf:initialXmlDocument caption="User Interface Developer Sample Form"
href="template.xml">
</xsf:initialXmlDocument>
</xsf:fileNew>
<!--Scripts-->
<xsf:scripts language="jscript">
<xsf:script src="internal.js"></xsf:script>
<xsf:script src="script.js"></xsf:script>
</xsf:scripts>
<!--Taskpane-->
<xsf:taskpane caption="Custom Task Pane" href="taskpane"></xsf:taskpane>
</xsf:xDocumentClass>