XForms Submission: Transmitting XML to a Server
This article provides a comprehensive overview of how the XForms
<submission> element handles the transmission of
instance XML data to a web server. It details the core attributes
governing the transmission, the serialization and validation processes,
the underlying HTTP transport mechanics, and how server responses are
managed within the XForms processing model.
The Role of the Submission Element
In XForms, the <submission> element acts as the
communication pipeline between the client-side form interface and the
server-side architecture. Unlike standard HTML forms that typically
flatten form data into URL-encoded key-value pairs, XForms preserves the
rich, hierarchical structure of XML data throughout the entire
transmission lifecycle.
Core Configuration Attributes
The behavior of the transmission is configured using several primary
attributes defined within the <submission>
element:
resource(oractionin XForms 1.0): Specifies the destination URI where the data should be sent.method: Defines the HTTP method used for the transmission, commonlypost,put,get, ordelete. For sending structured XML payloads,postandputare the standard choices.ref: Points to the specific node or subtree within the XML instance data that needs to be sent. If omitted, the entire root instance document is selected by default.mediatype(orserialization): Dictates the encoding format, typicallyapplication/xmlortext/xml, ensuring the receiving server recognizes the incoming payload as structured XML.replace: Determines how the client handles the server’s response. Values includeall(replaces the entire webpage),instance(updates the in-memory XML instance with the server’s response data), andnone(ignores the response body and keeps the current state).
The Transmission Process
The process of sending XML data via an XForms submission follows a strict, event-driven pipeline:
- Invocation: The submission is initiated either
automatically through an internal form event or explicitly via user
interaction, such as clicking a
<submit>control linked to the submission’s identifier. - Data Selection and Validation: The XForms processor
resolves the
refattribute to locate the target XML nodes. Before serialization, it evaluates all data constraints, such as required fields, data types, and custom validation rules defined in the<bind>elements. If validation fails, the submission halts, and anxforms-submit-errorevent is dispatched. - Serialization: Once validated, the selected in-memory XML DOM structure is serialized into an XML text stream. Standard XML declarations and character encodings (typically UTF-8) are applied.
- HTTP Request Execution: The processor constructs an
HTTP request targeting the designated URI. It sets the
Content-Typeheader (usually toapplication/xml; charset=UTF-8) and writes the serialized XML stream directly into the HTTP request body. - Response Handling: The server processes the XML
payload and returns an HTTP status code along with any response data.
Upon receiving a successful status code (such as
200 OK), the processor dispatches anxforms-submit-doneevent and applies the behavior specified by thereplaceattribute. If the server returns an error code (such as4xxor5xx), anxforms-submit-errorevent is triggered to allow error handling within the form.