<remark>Incorporated errata: (1) clarified rules regarding inclusion of option and value elements depending on field type; (2) clarified handling of default values; (3) added value elements to list-multi field in Example 2; (4) harmonized spelling of form-processing entity and form-submitting entity.</remark>
</revision>
<revision>
<version>2.6</version>
<date>2004-10-13</date>
<initials>psa</initials>
<remark>Incorporated errata: (1) corrected syntax of <reported/> element (<field/> element should not contain a <value/> child); (2) corrected Example 8.</remark>
</revision>
<revision>
<version>2.5</version>
<date>2004-05-07</date>
<initials>psa</initials>
<remark>Clarified terminology regarding form-processing entities and form-submitting entities; corrected several small errors in the schema.</remark>
<remark>Per discussion by the authors and Jabber Council, specified that the 'var' attribute is required for all field types except "fixed", for which the 'var' attribute is optional.</remark>
<remark>Formalization and further editorial revisions.</remark>
</revision>
<revision>
<version>2.2</version>
<date>2004-01-22</date>
<initials>psa</initials>
<remark>Editorial revisions.</remark>
</revision>
<revision>
<version>2.1</version>
<date>2003-02-16</date>
<initials>psa</initials>
<remark>Added schema.</remark>
</revision>
<revision>
<version>2.0</version>
<date>2002-12-09</date>
<initials>psa</initials>
<remark>Per a vote of the Jabber Council, changed status to Final.</remark>
</revision>
<revision>
<version>1.1</version>
<date>2002-10-15</date>
<initials>rwe</initials>
<remark>Call for Experience changes (see <linkurl="#draft-to-final">Changes Between Draft and Final</link> section). This version voted to Final on 2002-12-09.</remark>
</revision>
<revision>
<version>1.0</version>
<date>2002-04-24</date>
<initials>psa</initials>
<remark>Per a vote of the Jabber Council, changed status to Draft.</remark>
<p>Several existing Jabber/XMPP protocols involve the exchange of structured data between users and applications for common tasks such as registration (&xep0077;) and searching (&xep0055;). Unfortunately, these early protocols were "hard coded" and thus place significant restrictions on the range of information that can be exchanged. Furthermore, other protocols (e.g., &xep0045;) may need to exchange data for purposes such as configuration, but the configuration options may differ depending on the specific implementation or deployment. Finally, developers may want to extend other protocols (e.g., &xep0030;) in a flexible manner in order to provide information that is not defined in the base protocol. In all of these cases, it would be helpful to use a generic data description format that can be used for dynamic forms generation and data "modelling" in a variety of circumstances.</p>
<p>An example may be helpful. Let us imagine that when a user creates a multi-user chatroom on a text conferencing service, the service allows the user to configure the room in various ways. While most implementations will probably provide a somewhat common set of configurable features (discussion logging, maximum number of room occupants, etc.), there will be some divergence: perhaps one implementation will enable archiving of the room log in a variety of file types (XML, HTML, PDF, etc.) and for a variety of time periods (hourly, daily, weekly, etc.), whereas another implementation may present a boolean on/off choice of logging in only one format (e.g., daily logs saved in HTML). Obviously, the first implementation will have more configuration options than the second implementation. Rather than "hard-coding" every option via distinct XML elements (e.g., <room_logging_period/>), a better design would involve a more flexible format.</p>
<p>The 'jabber:x:data' protocol described herein defines such a flexible format for use by Jabber/XMPP entities, steering a middle course between the simplicity of "name-value" pairs and the complexity of &w3xforms; (on which development had just begun when this protocol was designed). In many ways, 'jabber:x:data' is similar to the Forms Module of &w3xhtml;; however, it provides several Jabber-specific data types, enables applications to require data fields, integrates more naturally into the "workflow" semantics of IQ stanzas, and can be included as an extension of existing Jabber/XMPP protocols in ways that the XHTML Forms Module could not when this protocol was developed (especially because &w3xhtmlmod; did not exist at that time).</p>
<li><strong>Data Gathering</strong> -- the protocol should enable a form-processing entity (commonly a server, service, or bot) to gather data from a form-submitting entity (commonly a client controlled by a human user); this should be done via distinct data fields (e.g., items in a questionnaire or configuration form), each of which can be a different data "type" and enable free-form input or a choice between multiple options (as is familiar from HTML forms).</li>
<li><strong>Data Reporting</strong> -- the protocol should enable a form-processing entity to report data (e.g., search results) to a form-submitting entity, again via distinct data fields.</li>
<li><strong>Portability</strong> -- the protocol should as much as possible define generic data formats and basic datatypes only; hints may be provided regarding the user interface, but they should be hints only and not hard-and-fast requirements.</li>
<li><strong>Simplicity</strong> -- the protocol should be simple for clients to implement, and most of the complexity (e.g., data validation and processing) should be the responsibility of servers and components rather than clients.</li>
<li><strong>Flexibility</strong> -- the protocol should be flexible and extensible rather than "hard-coded".</li>
<li><strong>Compatibility</strong> -- the protocol should define an extension to existing Jabber/XMPP protocols and not break existing implementations unless absolutely necessary.</li>
</ol>
</section1>
<section1topic='Protocol'anchor='protocol'>
<p>The base syntax for the 'jabber:x:data' namespace is as follows (a formal description can be found in the <linkurl="#schema">XML Schema</link> section below):</p>
<p>The &X; element qualified by the 'jabber:x:data' namespace SHOULD be included as a first-level child of an XML stanza; the stanza MAY be of any kind (&IQ;, &MESSAGE;, or &PRESENCE;), although it is RECOMMENDED to use &IQ; or &MESSAGE; (see also the restrictions enumerated below).</p>
<p>The OPTIONAL <title/> and <instructions/> elements enable the form-processing entity to label the form as a whole and specify natural-language instructions to be followed by the form-submitting entity. The XML character data for these elements SHOULD NOT contain newlines (the \n and \r characters), and any handling of newlines (e.g., presentation in a user interface) is unspecified herein; however, multiple instances of the <instructions/> element MAY be included.</p>
<p>The data gathered or provided in a 'jabber:x:data' form can be situated in a number of different contexts. Examples include an empty form that needs to be filled out, a completed form, the results of a submission, a search result, or simply a set of data that is encapsulated using the 'jabber:x:data' namespace. The full context for the data is provided by three things:</p>
<ol>
<li>the "wrapper" protocol (i.e., the namespace whose root element is the direct child of the &IQ; stanza and the parent of the &X; element qualified by the 'jabber:x:data' namespace)</li>
<li>the place of the form within a transaction (e.g., an IQ "set" or "result") or structured conversation (e.g., a message <thread/>)</li>
<li>the 'type' attribute on the form's root &X; element</li>
</ol>
<p>The first two pieces of contextual information are provided by other protocols, whereas the form types are described in the following table.</p>
<tablecaption='Form Types'>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td>form</td>
<td>The form-processing entity is asking the form-submitting entity to complete a form.</td>
</tr>
<tr>
<td>submit</td>
<td>The form-submitting entity is submitting data to the form-processing entity.</td>
</tr>
<tr>
<td>cancel</td>
<td>The form-submitting entity has cancelled submission of data to the form-processing entity.</td>
</tr>
<tr>
<td>result</td>
<td>The form-processing entity is returning data (e.g., search results) to the form-submitting entity, or the data is a generic data set.</td>
</tr>
</table>
<p>In order to maintain the context of the data as captured in the form type, the following rules MUST be observed:</p>
<ul>
<li><p>For &IQ; stanzas, the root element qualified by the "wrapper" namespace in a form of type "form" or "submit" MUST be returned in a form of type "result". The &X; element qualified by the 'jabber:x:data' namespace MUST be a child of the "wrapper" namespace's root element. As defined in &xmppcore;, the 'id' attribute MUST be copied in the IQ result. For data forms of type "form" or "result", the &IQ; stanza SHOULD be of type "result". For data forms of type "submit" or "cancel", the &IQ; stanza SHOULD be of type "set".</p></li>
<li><p>For &MESSAGE; stanzas, the <thread/> SHOULD be copied in the reply if provided. The &X; element qualified by the 'jabber:x:data' namespace MUST be a child of the &MESSAGE; stanza.</p></li>
<li><p>The only data form type allowed for <presence/> stanzas is "result". The &X; element qualified by the 'jabber:x:data' namespace MUST be a child of the &PRESENCE; stanza. In accordance with <cite>XMPP Core</cite>, use of data forms is not recommended unless necessary to provide information that is directly related to an entity's network availability.</p></li>
<section2topic='The Field Element'anchor='protocol-field'>
<p>A data form of type "form", "submit", or "result" SHOULD contain at least one <field/> element; a data form of type "cancel" SHOULD NOT contain any <field/> elements.</p>
<p>The <field/> element MAY contain any of the following child elements:</p>
<ul>
<li><p><strong><desc/></strong> -- The XML character data of this element provides a natural-language description of the field, intended for presentation in a user-agent (e.g., as a "tool-tip", help button, or explanatory text provided near the field). The <desc/> element SHOULD NOT contain newlines (the \n and \r characters), since layout is the responsibility of a user agent, and any handling of newlines (e.g., presentation in a user interface) is unspecified herein. (Note: To provide a description of a field, it is RECOMMENDED to use a <desc/> element rather than a separate <field/> element of type "fixed".)</p></li>
<li><p><strong><required/></strong> -- This element, which MUST be empty, flags the field as required in order for the form to be considered valid.</p></li>
<li><p><strong><value/></strong> -- The XML character data of this element defines the default value for the field (according to the form-processing entity), the data provided by a form-submitting entity, or a data result. In data forms of type "form", if the form-processing entity provides a default value via the <value/> element, then the form-submitting entity SHOULD NOT attempt to enforce a different default value (although it MAY do so to respect user preferences or anticipate expected user input). Fields of type list-multi, jid-multi, text-multi, and hidden MAY contain more than one <value/> element; all other field types MUST NOT contain more than one <value/> element.</p></li>
<li><p><strong><option/></strong> -- One of the options in a field of type "list-single" or "list-multi". The XML character of the <value/> child defines the option value, and the 'label' attribute defines a human-readable name for the option. The <option/> element MUST contain one and only one <value/> child. If the field is not of type "list-single" or "list-multi", it MUST NOT contain an <option/> element.</p></li>
</ul>
<p>If the <field/> element type is anything other than "fixed" (see below), it MUST possess a 'var' attribute that uniquely identifies the field in the context of the form (if it is "fixed", it MAY possess a 'var' attribute). The <field/> element MAY possess a 'label' attribute that defines a human-readable name for the field. For data forms of type "form", each <field/> element SHOULD possess a 'type' attribute that defines the data "type" of the field data (if no 'type' is specified, the default is "text-single"); fields provided in the context of other forms types MAY possess a 'type' attribute as well.</p>
<p>If fields are presented in a user interface (e.g., as items in a questionnaire or form result), the order of the field elements in the XML SHOULD determine the order of items presented to the user.</p>
<p>The following field types represent data "types" that are commonly exchanged between Jabber/XMPP entities. These field types are not intended to be as comprehensive as the datatypes defined in, for example, &w3xmlschema2;, nor do they define user interface elements.</p>
<tablecaption='Field Types'>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td>boolean</td>
<td>The field enables an entity to gather or provide an either-or choice between two options. The default value is "false". &BOOLEANNOTE;</td>
</tr>
<tr>
<td>fixed</td>
<td>The field is intended for data description (e.g., human-readable text such as "section" headers) rather than data gathering or provision. The <value/> child SHOULD NOT contain newlines (the \n and \r characters); instead an application SHOULD generate multiple fixed fields, each with one <value/> child.</td>
</tr>
<tr>
<td>hidden</td>
<td>The field is not shown to the form-submitting entity, but instead is returned with the form.</td>
</tr>
<tr>
<td>jid-multi *</td>
<td>The field enables an entity to gather or provide multiple Jabber IDs.</td>
</tr>
<tr>
<td>jid-single *</td>
<td>The field enables an entity to gather or provide a single Jabber ID.</td>
</tr>
<tr>
<td>list-multi</td>
<td>The field enables an entity to gather or provide one or more options from among many.</td>
</tr>
<tr>
<td>list-single</td>
<td>The field enables an entity to gather or provide one option from among many.</td>
</tr>
<tr>
<td>text-multi **</td>
<td>The field enables an entity to gather or provide multiple lines of text.</td>
</tr>
<tr>
<td>text-private</td>
<td>The field enables an entity to gather or provide a single line or word of text, which shall be obscured in an interface (e.g., *****).</td>
</tr>
<tr>
<td>text-single</td>
<td>The field enables an entity to gather or provide a single line or word of text, which may be shown in an interface. This field type is the default and MUST be assumed if a form-submitting entity receives a field type it does not understand.</td>
<p>* Note: Data provided for fields of type "jid-single" or "jid-multi" MUST contain one or more valid Jabber IDs, where validity is determined by the addressing rules defined in <cite>XMPP Core</cite> (see the <linkurl='#validation'>Data Validation</link> section below).</p>
<p>** Note: Data provided for fields of type "text-multi" SHOULD NOT contain any newlines (the \n and \r characters). Instead, the application SHOULD split the data into multiple strings (based on the newlines inserted by the platform), then specify each string as the XML character data of a distinct <value/> element. Similarly, an application that receives multiple <value/> elements for a field of type "text-multi" SHOULD merge the XML character data of the value elements into one text block for presentation to a user, with each string separated by a newline character as appropriate for that platform.</p>
</section2>
<section2topic='Multiple Items in Form Results'anchor='protocol-results'>
<p>In some contexts (e.g., the results of a search request), it may be necessary to communicate multiple items. Therefore, a data form of type "result" MAY contain two child elements not described in the basic syntax above: one <reported/> element followed by zero or more <item/> elements. The syntax is as follows:</p>
<p>Each of these elements MUST contain one or more <field/> children. The <reported/> element defines the data format for the result items by specifying the fields to be expected for each item; for this reason, the <field/> elements SHOULD possess a 'type' attribute and 'label' attribute in addition to the 'var' attribute, and SHOULD NOT contain a <value/> element. Each <item/> element defines one item in the result set, and MUST contain each field specified in the <reported/> element (although the XML character data of the <value/> element MAY be null).</p>
<p>Data validation is the responsibility of the form-processing entity (commonly a server, service, or bot) rather than the form-submitting entity (commonly a client controlled by a human user). This helps to meet the requirement for keeping client implementations simple. If the form-processing entity determines that the data provided is not valid, it SHOULD return a "Not Acceptable" error, optionally providing a textual explanation in the XMPP <text/> element or an application-specific child element that identifies the problem (see &xep0086; for information about mappings and formats).</p>
<p>For the sake of the following examples, let us suppose that there exists a bot hosting service on the Jabber network, located at <botster.shakespeare.lit>. This service enables registered users to create and configure new bots, find and interact with existing bots, and so on. We will assume that these interactions occur using the &xep0050; protocol, which is used as a "wrapper" protocol for data forms qualified by the 'jabber:x:data' namespace. The examples in the sections that follow show most of the features of the data forms protocol described above.</p>
<p>Note: Additional examples can be found in the specifications for various using protocols, such as <cite>XEP-0045: Multi-User Chat</cite> and <cite>XEP-0055: Jabber Search</cite>.</p>
<p>The first step is for a user to create a new bot on the hosting service. We will assume that this is done by sending a "create" command to the desired bot:</p>
<p>Now that the user has created this search bot, let us suppose that one of the friends he has invited decides to try it out by sending a search request:</p>
<p>There are no security concerns related to this specification above and beyond those described in the relevant section of <cite>XMPP Core</cite>.</p>
<p>The XMPP Registrar maintains a registry of parameter values related to the 'jabber:x:data' namespace, specifically as defined in &xep0068;; the registry is located at &FORMTYPES;.</p>
When contained in a "reported" element, the "field" element
SHOULD NOT contain a "value" child.
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:elementname='item'>
<xs:complexType>
<xs:sequence>
<xs:elementref='field'maxOccurs='unbounded'/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleTypename='empty'>
<xs:restrictionbase='xs:string'>
<xs:enumerationvalue=''/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
]]></code>
</section1>
<section1topic='Changes Between Draft and Final'anchor='draft-to-final'>
<p>The following protocol changes were incorporated in the Final specification as a result of experience with the Draft specification (described in version 1.0 of this document):</p>
<ul>
<li>The <x/> element MAY be included in <message/> and <presence/> elements.</li>
<li>The <x/> element MAY contain a <title/> child for forms and results.</li>
<li>The <x/> element MUST possess a 'type' attribute.</li>
<li>A <field/> element MAY be of type='jid-single'.</li>
<li>Results MAY be reported back in <item/> tags.</li>
<li>Results MAY contain a <reported/> element with result set.</li>
<li>The <reported/> fields MAY possess a 'type' attribute to provide hints about how to interact with the data (type='jid-single' being the most useful).</li>