411 REFERENCE · Wikibooks
XForms/Changing Namespaces in Submission
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Motivation
You want to control the way that namespace prefixes are handled in your submission.
Method
We will use the includenamespaceprefixes attribute of a submission.
The XForms 1.1 specification allows the user to change the way that namespace prefixes are handled in a submitted element.
Here is an example of the use of the includenamespaceprefixes attribute to the submission element.
<xf:submission action="http://example.com/submit"
method="post" id="submit"
includenamespaceprefixes=""/>
<xf:submission action="http://example.com/submit"
method="post" includenamespaceprefixes="#default"/>
Sample Form
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:task="http://www.example.com/task"
task:dummy="dummy">
<head>
<title>Test of XForms Submission Namespace Inclusion</title>
<style type="text/css">
<![CDATA[
@namespace xf url("http://www.w3.org/2002/xforms");
body {font-family:Helvetica, sans-serif;}
.block-form xf|input { display: block; margin: 1ex; }
.block-form xf|label {display: inline-block; width: 15ex; float: left; text-align: right; margin-right: 1ex; font-weight: bold;}
]]>
</style>
<xf:model>
<xf:instance src="input-default-ns.xml" id='save-data'/>
<xf:submission id="submit-std"
action="http://localhost:8080/exist/rest/db/test/xforms/submission-tests/save-new.xq"
method="post"/>
<xf:submission id="submit-null"
action="http://localhost:8080/exist/rest/db/test/xforms/submission-tests/save-new.xq"
method="post"
includenamespaceprefixes=""/>
<xf:submission id="submit-default"
action="http://localhost:8080/exist/rest/db/test/xforms/submission-tests/save-new.xq"
method="post"
includenamespaceprefixes="#default"/>
</xf:model>
</head>
<body>
<h1>Submit Test</h1>
<div class="block-form">
<xf:input ref="instance('save-data')/task:id">
<xf:label>ID: </xf:label>
</xf:input>
<xf:input ref="task:task-name">
<xf:label>Name: </xf:label>
</xf:input>
<xf:input ref="task:task-description">
<xf:label>Description: </xf:label>
</xf:input>
</div>
<xf:submit submission="submit-std">
<xf:label>Without Attribute</xf:label>
</xf:submit>
<xf:submit submission="submit-null">
<xf:label>With Attribute Null</xf:label>
</xf:submit>
<xf:submit submission="submit-default">
<xf:label>With Default Namespace</xf:label>
</xf:submit>
</body>
</html>
Sample Instance Files
With Default Namespace
<task xmlns="http://www.example.com/task">
<task:id>123</task:id>
<task-name>Task Name</task-name>
<task-description>Task Description</task-description>
</task>
With Namespace Prefixes
<task:task xmlns:task="http://www.example.com/task">
<task:task:id>123</task:id>
<task:task-name>Task Name</task:task-name>
<task:task-description>Task Description</task:task-description>
</task:task>
Link to Working Example
Example
Introduction to XForms 1.1 Submission Differences
Events Overview Encoding Parameters