Home arrow XML arrow Page 4 - XForms Basics, Part 2

A Custom Job - XML

In the first part of this series, I gave you a quick introduction to the newly-released XForms 1.0 specification, by explaining the fundamental concepts of the XForms model. Now that you know the basics, find out how to submit XForms data to a server-side script or save it to a local client file, and also read about how XForms can integrate with XML Schemas to simplify input validation.

TABLE OF CONTENTS:
  1. XForms Basics, Part 2
  2. Welcome to Immigration
  3. Data Overload
  4. A Custom Job
  5. Not My Type
  6. The Number Game
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 8
January 14, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

In addition to the attributes you've already seen, the <xforms:submission> element also comes with a bunch of others, which can assist in customizing the manner in which the form data is submitted. Here's a brief list:

ref - Specifies the node to use as root when submitting instance data, defaults to /.

version - Specifies XML version to use when submitting form data.

indent - Toggles indenting of XML data in form submission.

encoding - Specifies XML encoding to use when submitting form data.

omit-xml-declaration - Toggles XML declaration when submitting form data.

standalone - Toggles standalone declaration when submitting form data.

replace - Specifies what to do with the response to the submission.

Consider the following example, which demonstrates some of these in action:


<html xmlns=<A href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</A>
xmlns:xforms="http://www.w3.org/2002/xforms/cr">
<head>
<!-- 
form model -->
<xforms:model id="information">
 
<xforms:instance>
  
<user>
   
<name />
   
<email />
   
<age />
  
</user>
 
</xforms:instance>
 
<xforms:submission id="submit" 
  ref
="/user/name" action="/tmp/user.xml" 
  method
="put" indent="yes" 
  omit
-xml-declaration="no" />
 
</xforms:model>
<basefont face="Arial">
</
head>
<
body>
<!-- 
define interface controls -->
<table cellspacing="5" cellpadding="5" 
  border
="0">
<tr>
<td>
 
<xforms:input id="txtname" 
  model
="information" ref="/user/name">
  
<xforms:label>Name</xforms:label>
  
<xforms:hint>Enter your name 
                    here
</xforms:hint>
 
</xforms:input>
</td>
</tr>
<
tr>
<td>
 
<xforms:input id="txtemail" 
   model
="information" ref="/user/email">
  
<xforms:label>Email address
  
</xforms:label>
  
<xforms:hint>Enter your email address 
                    here
</xforms:hint>
 
</xforms:input>
</td>
<
td>
 
<xforms:input id="txtage" 
  
model="information" ref="/user/age">
  
<xforms:label>Age</xforms:label>
  
<xforms:hint>Enter your age 
                    here
</xforms:hint>
 
</xforms:input>
</td>
</
table>
<
xforms:submit submission="submit">
 
<xforms:label>Save</xforms:label>
 
<xforms:hint>Save the information 
 entered above to a local file
</xforms:hint>
</xforms:submit>
</
body>
</html>

In this case, I've explicitly told the XForms processor to include the XML declaration in the final form submission, but to only include that part of the instance data tree beginning with the element <name>. Here's the output:

[output]
<?xml version="1.0" encoding="ISO-8859-1"?>

<name>Harish</name>
[/output]

It's important to note, also, that XForms supports submitting data in more than just PUT and POST methods, and that if you really need to, you can even replicate the behavior of traditional HTML forms by submitting your data in the standard name=value format. The method attribute of the <xforms:submission> element can take any of the values "post", "get", "put", "multipart-post", and "form-data-post." Take a look at the specification to see what each one of these does.



 
 
>>> More XML Articles          >>> More By Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

XML ARTICLES

- Google Docs and Xpath Data Functions
- Flex Array Collection Sort and Filtering
- The Flex Tree Control
- Flex List Controls
- Working with Flex and Datagrids
- How to Set Up Podcasting and Vodcasting
- Creating an RSS Reader Application
- Building an RSS File
- An Introduction to XUL Part 6
- An Introduction to XUL Part 5
- An Introduction to XUL Part 4
- An Introduction to XUL Part 3
- An Introduction to XUL Part 2
- An Introduction to XUL Part 1
- XML Matters: Practical XML Data Design and M...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: