Cover | Table of Contents | Colophon
http://www.cnn.com, I counted six separate
forms:form element and
related markup from either HTML or XHTML. Using HTML forms, searching
for information became possible on a worldwide scale. Sites such as
Yahoo! quickly became the most popular
"portals" of entry on the Web.
Later, as developers pushed the limits of forms technology farther,
web sites became even more interactive and customizable. In return
for a small piece of information, such as a postal code, the browsing
experience could be reshaped to include what specific information
visitors were looking for—leaving out the rest. HTML forms have
proven so successful in this regard that newer web technologies, such
as PDF forms and Flash, have been unable to make a significant dent
in their popularity.form. This element
describes some important aspects of the form, including where and how
to submit data. The content of this element consists of regular HTML
markup, as well as controls.<input type="text" name="name" value="Dubinko, Micah"/>
src attribute to an existing XML data source.string, money, and
group, where the tags needed to be nested in a
structure that mirrored the desired shape of the final XML that would
be submitted. For example, to submit XML that looked like:<poll> <vote>Vanilla</vote> </poll>
<xform>
<group name="poll">
<string name="vote">
</group>
</xform>
<select1 ref="mainsel" appearance="radio" selection="open">
<label>Poll: to be or not to be?</label>
<item>
<label>To Be</label>
<value>b</value>
</item>
<item>
<label>Not To Be</label>
<value>n</value>
</item>
</select1>
<model> <submission action="http://example.info/xml-submit"/> </model>
select1.
Note, too, that the "Other, please
specify" choice isn't needed, since
XForms supports open selection lists natively. If the user manually
entered http://dubinko.info/writing/xforms/ubl/.
<Order xmlns="urn:oasis:names:tc:ubl:Order:1.0:0.70"
xmlns:cat="urn:oasis:names:tc:ubl:CommonAggregateTypes:1.0:0.70">
<cat:ID/>
<cat:IssueDate/>
<cat:LineExtensionTotalAmount currencyID="USD"/>
<cat:BuyerParty>
<cat:ID/>
<cat:PartyName>
<cat:Name/>
</cat:PartyName>
<cat:Address>
<cat:ID/>
<cat:Street/>
<cat:CityName/>
<cat:PostalZone/>
<cat:CountrySub-Entity/>
</cat:Address>
<cat:BuyerContact>
<cat:ID/>
<cat:Name/>
</cat:BuyerContact>
</cat:BuyerParty>
<cat:SellerParty>
<cat:ID/>
<cat:PartyName>
<cat:Name/>
</cat:PartyName>
<cat:Address>
<cat:ID/>
<cat:Street/>
<cat:CityName/>
<cat:CountrySub-Entity/>
</cat:Address>
</cat:SellerParty>
<cat:DeliveryTerms>
<cat:ID/>
<cat:SpecialTerms/>
</cat:DeliveryTerms>
<cat:OrderLine>
<cat:BuyersID/>
<cat:SellersID/>
<cat:LineExtensionAmount currencyID=""/>
<cat:Quantity unitCode="">1</cat:Quantity>
<cat:Item>
<cat:ID/>
<cat:Description>Enter description here</cat:Description>
<cat:SellersItemIdentification>
<cat:ID>Enter part number here</cat:ID>
</cat:SellersItemIdentification>
<cat:BasePrice>
<cat:PriceAmount currencyID="">0.00</cat:PriceAmount>
</cat:BasePrice>
</cat:Item>
</cat:OrderLine>
</Order>XForms is not a free-standing document type, but is intended to be integrated into other markup languages, such as XHTML or SVG.
head section can contain the XForms
Model, and in SVG, a foreignObject element can
enclose individual form controls.src, has caused nearly as much controversy as its
big brother in XHTML,
href. The problem stems
from tension with XLink 1.0, a W3C Recommendation, which
asserts itself as the preferred technique to define any
"explicit relationship between resources or portions
of resources." Originally, this standard was
envisioned by some as a solution that could apply to any XML, but the
final solution worked only with an attribute named
xlink:href (complete with a separate namespace).xlink:href):<xforms:label src="label2.svg" xlink:href="homepage.html"/>
src attribute from XForms
points to a SVG file to be used as the label, and the
xlink:href attribute from SVG makes the label a
clickable hyperlink to homepage.html.
It's a good thing that the XForms attribute is named
src and not xlink:href, because
a conflict would have resulted when trying to combine the languages,
since an element can't have two attributes with the
same name.src
consistently means one thing: that the URI in the attribute value is
to be fetched as part of loading the document, and the contents
rendered in place of whatever element contains the attribute (much
like the img element in earlier versions of
XHTML).http://www.w3.org/TR/xpath), a
component of
XSLT
(http://www.w3.org/TR/xslt), an
XML vocabulary used for transforming one flavor of XML into another.
The XPath specification was built with the intention that later
specifications could use it as a foundation, which is exactly what
XForms does. This chapter first lays out the foundation of XPath, and
then shows how XForms builds on that foundation./html/head/title
html:head/xforms:model/@xml:id
../items
purchaseOrder/items/item[3]
purchaseOrder/items/item[@price = 12.34]
string-length('hello world')
purchaseOrder/subtotal * instance('taxtable')/tax
total * instance('taxtable')/rate
/html/head/title
html, head, and
title. The XML referenced by this path might look
something like this:<html>
<head>
<title>Push Button Paradise</title>
...
@
character, leading to XPath expressions like this:html:head/xforms:model/@id
DOCTYPE declaration produce any nodes. Thus, these
XML data structures are effectively invisible to XPath and, by
extension, XForms. On the other hand, notice how each element node
has two
namespace nodes attached: one for the
xmlns:html declaration on the root element, which
applies throughout, and one for the built-in declaration of the
xml prefix, as seen in the attribute
xml:lang. Even a short document like this
generates a huge number of nodes!<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<?xml-stylesheet href="screen.css" type="text/css" media="screen"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Virtual Library</title>
</head>
<body>
<p>Moved to <a href="http://vlib.example.org/">vlib.example.org</a>.</p>
</body>
</html>/). Each
individual step builds upon the previous steps to traverse the
document, and can be a test against the name of a node, or one of the
following special tests:node( )
text( )
comment( )
processing-instruction( )
*, which will match any
element node (or attribute node within the
attribute axis, or namespace node within the
namespace axis.) Similarly, another special test
prefix:* will
match any node identified with the namespace mapped to
prefix.
<html:html xmlns:html="http://www.w3.org/1999/html">
<html:head>
<html:title>Mutant Registration Guidelines</html:title>
</html:head>
<html:body>
<html:p>The White House announced today...</html:p>
</html:body>
</html:html>
html:html. Thus, to bind a form control to the
document title, instead of the longer absolute path
/html:html/html:head/html:title, a shorter
relative path html:head/html:title could be used.
The key difference between the two is that absolute paths contain a
leading slash and the name of the root element. Since there can be
only one root element, including its name in every path expressions
isn't necessary—path expressions
don't become ambiguous by leaving out what is really
a redundant step along the path.ref attribute
possibly with the model attribute, or
alternatively the bind attribute. Either way, the
expression selects a node-set from the instance data, and the first
node, in document order, is used as the context node for child
elements. Chapter 10 shows a way to take advantage
of this behavior to greatly simplify the use of XPath in XForms.<bind> element.
The nodeset attribute on this element selects an
XPath node-set, applying certain properties such as
calculate to each node. This means that the
expression used will get evaluated multiple times, once for each node
in the node-set. Upon each evaluation, the node being processed is
the context node. This is most useful when a calculation appears in a
repeating section. In the following example, each individual line
item has a calculation that runs within the current line item only:boolean datatype can represent true as either
1 or true, (and false as either
0 or false). Even though there
are multiple possible representations, they both map to the
underlying concept of trueness and
falseness, respectively. This is important when
comparing values; the value space is used as the basis for
comparison.P1DT1H. From the perspective of the person filling
out a form, this is complete gibberish. To work around this, XForms
gives responsibility to individual form controls to present data to
the user in a manner that's convenient to the
intended audience. Thus, XForms introduces (but
doesn't specifically name) a third space, the
user space. For
the benefit of users, this might not be a straightforward
mapping—the form control can have great latitude in rearranging
things, such as a graphical calendar control to enter durations and
dates.boolean datatype can represent true as either
1 or true, (and false as either
0 or false). Even though there
are multiple possible representations, they both map to the
underlying concept of trueness and
falseness, respectively. This is important when
comparing values; the value space is used as the basis for
comparison.P1DT1H. From the perspective of the person filling
out a form, this is complete gibberish. To work around this, XForms
gives responsibility to individual form controls to present data to
the user in a manner that's convenient to the
intended audience. Thus, XForms introduces (but
doesn't specifically name) a third space, the
user space. For
the benefit of users, this might not be a straightforward
mapping—the form control can have great latitude in rearranging
things, such as a graphical calendar control to enter durations and
dates.pattern facet, which works on the lexical space.)xs:string is the
default datatype that XForms will use, unless the author specifies
otherwise.xs:string punts on all whitespace processing, so
all tab characters and newline characters pass through unchanged. If
this is undesired, it is better to use a more restricted datatype
such as xs:normalizedString or
xforms:listItem.xs:string is that all whitespace characters are
converted into space (0x20) characters.xs:double can do anything
xs:float can do and more. If you need to capture
floating point values, use xs:double.xs:duration, except as an abstract base type for
xforms:dayTimeDuration and
xforms:yearMonthDuration. These derived types
should always be used instead of xs:duration.xs:date.<xs:simpleType name="email">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Za-z0-9!#-'\*\+\-/=\?\^_`\{-~]+
(\.[A-Za-z0-9!#-'\*\+\-/=\?\^_`\{-~]+)*@[A-Za-z0-9!#-
'\*\+\-/=\?\^_`\{-~]+(\.[A-Za-z0-9!#-'\*\+\-/=\?\^_`\
{-~]+)*"/>
</xs:restriction>
</xs:simpleType>
"!" "#" "$" "%" "&" "'" "*" "+" "-" "/" "=" "?" "^" "_" "`" "{" "|" "}" "~"
[A-Za-z0-9!#-'\*\+\-/=\?\^_`\{-~]
atext+ (\. atext+)* @ atext+ (\. atext+)*
xsi:type, which can be placed directly on XML
instance data elements, even if a pre-existing Schema
doesn't permit the attribute. For existing XML that uses this with
simpleTypes, such as those described earlier in this chapter, this is
a reasonable course. If the xsi:type identifies a
complexType, however, all the problems in the previous section apply.
For new development, the less intrusive XForms type model item
property should be used, as described at Chapter 5.instance element,
which can either point to or directly contain XML. Either way, this
XML is parsed to create nodes in the instance data. (Another
possibility is during "lazy author"
processing, where the
instance data nodes are built from
scratch, without need of any author-provided XML.) The distinction
between instance and instance data is subtle; a good comparison
might be between the hard markup in a web page, as seen with the View
Source command, and the in-memory representation accessible from the
DOM. In nearly every case, XForms works from the internal instance
data, ignoring the document markup. As a consequence, selecting View
Source in the browser will always show the document as it was when it
initially loaded, and any changes made because of XForms activity
won't be visible.