W3Schools

home HOME

XForms Tutorial
XForms HOME
XForms Intro
XForms Model
XForms Namespace
XForms Example
XForms XPath
XForms Input
XForms Selections
XForms Datatypes
XForms Properties
XForms Actions
XForms Functions

References
XForms Datatypes

Selected Reading
Web Statistics
Web Glossary
Web Hosting
Web Quality

W3Schools Forum

Helping W3Schools

XForms And XPath

prev next

XForms uses XPath to address data. This is called binding.


XForms Binding

XForms uses two sections to define data: The XForms model and the XForms user interface.

The XForms model is an XML template (instance) for the data, and the XForms user interface is a description of the input and display of the data.

XForms uses XPath to define the connection between the two sections. This is called binding.


XPath

XPath is a W3C standard syntax for defining parts of XML documents.

XPath uses path expressions to identify nodes in an XML document. These path expressions look much like the expressions you see when you work with a computer file system.

This XPath expression:

/person/fname

addresses the fname node in the XML document:

<person>
   <fname>Hege</fname>
   <lname>Refsnes</lname>
</person>

Learn more about XPath in our XPath tutorial


Binding Using Ref

With an XForms model instance like this:

<instance>
  <person>
    <name>
      <fname/>
      <lname/>
    </name>
  </person>
</instance>

The XForms user interface can bind <input> elements using the ref attribute:

<input ref="name/fname">
<label>First Name</label>
</input>
<input ref="name/lname">
<label>Last Name</label>
</input>

The ref="name/fname" attribute in the example above is an XPath expression pointing to the <fname> element in the instance model. This binds the input field to the <fname> element in the XML document (instance) that is collecting data from the form.

The XForms user interface could also use a reference like this:

<input ref="/person/name/fname">
<label>First Name</label>
</input>
<input ref="/person/name/lname">
<label>Last Name</label>
</input>

In the example above, the slash (/) at the beginning of the XPath expression indicates the root of the XML document.


Binding Using Bind

With an XForms model instance like this:

<model>
<instance>
  <person>
    <name>
      <fname/>
      <lname/>
    </name>
  </person>
</instance>
<bind nodeset="/person/name/fname" id="firstname"/>
<bind nodeset="/person/name/lname" id="lastname"/>
</model>

The XForms user interface can bind <input> elements using the bind attribute:

<input bind="firstname">
<label>First Name</label>
</input>
<input bind="lastname">
<label>Last Name</label>
</input>

Why two different ways to bind input control elements to instance data?

Well, when you start using XForms in complex applications, you will find binding using bind to be a more flexible way to deal with multiple forms and multiple instance models.


prev next


Want To Be A Web Master?

If you want to be a Web Master, you will have to host your web site with an ISP (Internet Service Provider).

MaximumASP offers seven different configurations of dedicated servers to meet your Windows and .NET hosting needs. Hosted on our multi-tiered Enterprise Class network, these servers provide the performance, security and reliability you need to host your high end web sites and applications.

Visit MaximumASP




Jump to: Top of Page or HOME or Printer Friendly Printer friendly page

W3Schools provides material for training only. We do not warrant the correctness of its contents. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 1999-2008 by Refsnes Data. All Rights Reserved.

Validate Validate W3C-WAI level A conformance icon W3Schools was converted to XHTML in December 1999
SITE SEARCH
 
About W3Schools
W3Schools Forum
Shopping Cart
ASP.NET
Shopping Cart
WEB HOSTING
$15 Domain Name
Registration
Save $20 / year!
UK Domain Names
UK Web Hosting

Alojamiento Web
Buy UK Domain Names
Register Domain Names
Cheap Domain Names
Cheap Web Hosting
Best Web Hosting
Domain Name Registration
PHP MySQL Hosting
Top 10 Web Hosting
Web Hosting Providers
Web Hosting Company
UK Web Hosting
UK Reseller Hosting
Web Hosting
WEB BUILDING
Website Templates
Flash Templates
Website Builder
Internet Business Opportunity
Custom Programming
FREE Trial or Demo
Web Content Manager
Forms,Web Alerts,RSS
Ecommerce Software
Learn XML with XMLSpy®
Azbuz Blog
SHOPPING
UK Wholesalers
UK Wholesale
UAE Dubai Property
Private Student Loans
UK Dropshippers & Wholesalers Directory
EDUCATION
US Web Design Schools
HTML Exam
YELLOW PAGES
www.nettkatalogen.no
www.gulex.dk
www.gulex.se
www.gelbex.de
www.teloos.fi
www.teloos.fr
www.teloos.co.uk
www.teloos.at
www.teloos.de