ch02_XForm Essentials.pdf
(
288 KB
)
Pobierz
Chapter 2
CHAPTER 2
XForms Building Blocks
“What the world really needs is more love and
less paperwork.”
—-Pearl Bailey
“XML lets organizations benefit from structured,
predictable documents. Thus, XML breeds forms.
QED.”
—-David Weinberger
The previous chapter ended with a look at the simple syntax of XForms.
This chapter goes into greater detail on the concepts underlying the design
of XForms, as well as practical issues that come into play, including a com-
plete, annotated real-world example.
A key concept is the relationship between forms and documents, which will
be addressed first. After that, this chapter elaborates on the important issue
of host languages and how XForms integrates them.
More Than Forms
Despite the name, XForms is being used for many applications beyond sim-
ple forms. In particular, creating and editing XML-based documents is a
good fit for the technology.
A key advantage of XML-based documents over, say, paper or word proces-
sor templates, is that an entirely electronic process eliminates much uncer-
tainty from form processing. Give average “information workers” a paper
form, and they’ll write illegibly, scribble in the margins, doodle, write in new
choices, and just generally do things that aren’t expected. All of these behav-
iors are manually intensive to patch up, in order to clean the data to a point
19
where it can be placed into a database. With XForms, it is possible to restrict
the parts of the document that a user is able to modify, which means that
submitted data needs only a relatively light double-check before it can be
sent to a database. (One pitfall to avoid, however, is a system that is exces-
sively restrictive, so that the person filling the form is unable to accurately
provide the needed data. When that happens, users typically give bad infor-
mation or avoid the electronic system altogether.)
Various efforts are underway to define XML vocabularies for all sorts of doc-
uments. Perhaps one of the most ambitious is UBL, the Universal Business
Language, currently being standardized through OASIS (the Organization
for the Advancement of Structutured Information Standards). The goal of
UBL is to represent all different sorts of business documents—purchase
orders, invoices, order confirmations, and so on—using a family of XML
vocabularies. XForms is a great tool with which to create and edit UBL doc-
uments.
A Real-World Example
As an example, this section will develop an XForms solution for creating and
editing a UBL purchase order. The first step is to define the initial instance
data, which is a skeleton XML document that contains the complete struc-
ture of the desired final document, but with only initial data. This docu-
ment serves as a template for newly-created purchase orders, and provides a
framework on which to hang the rest of the form.
This complete example form is available online at
http://
dubinko.info/writing/xforms/ubl/.
Example 2-1 shows what a UBL purchase order document looks like.
Figure 2-1 shows, in the X-Smiles browser, an XForms document capable of
creating such a document.
20 |
Chapter 2: XForms Building Blocks
Figure 2-1. An XML purchase order being created with XForms
Example 2-1. An XML purchase order using 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>
A Real-World Example |
21
Example 2-1. An XML purchase order using UBL (continued)
<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>
The markup used by UBL seems slightly verbose, but this is necessary to
capture all the small variations that occur in the purchase orders used by dif-
ferent organizations. Note that the
cat:OrderLine
element can repeat as
many times as necessary, though only a single occurrence is needed for the
initial instance data. Also note that the root element uses a different XML
namespace than the rest of the document. Thanks to the context node rules
in XForms, the root element never needs to be directly referred to, and thus
form authors can happily ignore this minor detail.
The next step is to create an XForms document that will serve to edit the ini-
tial instance data. XForms itself does not define a document format. Instead,
a host language such as XHTML or SVG, combined with XForms, needs to
be used. As of this writing, XHTML 2.0, which natively includes XForms, is
22 |
Chapter 2: XForms Building Blocks
Plik z chomika:
musli_com
Inne pliki z tego folderu:
Addison.Wesley.PHP.and.MySQL.Web.Development.4th.Edition.1009pp.10-2008.pdf
(12306 KB)
Drupal for Education and E-Learning, 2nd Edition.pdf
(31542 KB)
Apress Beginning PHP and MySQL, 3rd ed. (2008).pdf
(14098 KB)
Beginning CSS Cascading Style Sheets for Web Design.pdf
(16614 KB)
Beginning iPhone and iPad Web Apps.pdf
(17336 KB)
Inne foldery tego chomika:
3D Design - Programming
ActionScript
Actionscript - Flash - Flex - Air
Ada
ADO
Zgłoś jeśli
naruszono regulamin