w3schools
  
HOME HTML CSS XML JAVASCRIPT ASP PHP SQL MORE...   References Examples Forum About

XForms and XPath

« Previous Next Chapter »

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.


« Previous Next Chapter »

Free Online Website Builder - No Downloading Needed

Create a free Flash website with our simple, online web design editing platform. Stunning templates and user-friendly tools make website building easy and fun.

Start Creating your free website now!


Altova® MapForce®
Graphical XML Mapping Tool from the Developers of XMLSpy®

Altova MapForce

Need an easy way to get data into XML, or transform XML to another format? MapForce lets you map XML data to/from any combination of XML, database, flat file, Excel 2007, XBRL, or Web services data. Then it transforms data instantly or auto-generates royalty-free code for recurrent conversions. New features in Version 2010!

  • Easy-to-use, graphical data mapping interface
  • Instant data transformation
  • XSLT 1.0/2.0 and XQuery code generation
  • Java, C#, and C++ code generation
  • Advanced data processing functions
  • Support for all major relational databases including SQL Server, IBM DB2, Oracle, and more
  • Visual Studio & Eclipse integration
  • Available in 32-bit and 64-bit versions

Download a fully-functional trial today!

  Altova MapForce


WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Top 10 Web Hosting
UK Reseller Hosting
Web Hosting
FREE Web Hosting
Top Web Hosting
Cheap UK Web Hosting
WEB BUILDING
XML Editor – Free Trial!
FREE Flash Website
FREE Web Templates
SEO Company
EDUCATION
US Web Design Schools
HTML Certification
JavaScript Certification
XML Certification
PHP Certification
ASP Certification
STATISTICS
Browser Statistics
Browser OS
Browser Display
FLIGHT TICKETS
Find the cheapest flight
to any destination now!
SHARE THIS PAGE