XForms and XPath
- Previous Page XForms Example
- Next Page XForms Input
XForms uses XPath for acute addressing of data. This process is called binding.
XForms Binding
XForms uses two parts to define data: XForms model and XForms user interface.
XForms models are XML templates (instances) for data, and XForms user interfaces are descriptions of data input and display.
XForms uses XPath to define the connection between these two parts. This is calledBinding (binding).
XPath
XPath is used to define the standard syntax for the various parts of an XML document, as defined by the W3C.
XPath uses path expressions to identify nodes in XML documents. These expressions are very similar to the file path expressions you see in computer systems.
XPath Expression:
/person/fname
Addressing the <fname> node in the XML document:
<person> <fname>David</fname> <lname>Smith</lname> </person>
our XPath Tutorial Learn more about XPath in our
Binding with Ref
The XForms model is like this:
<instance> <person> <name> <fname/> <lname/> </name> </person> </instance>
The XForms user interface can use ref attribute tobinding The <input> element:
<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 above example is an XPath expression pointing to the <fname> element in the instance model. It can be used tobindingto the <fname> element in the XML document (instance) collected from the form.
The XForms user interface can also use references:
<input ref="/person/name/fname"> <label>First Name</label> </input>
<input ref="/person/name/lname"> <label>Last Name</label> </input>
In the above example, the forward slash (/) at the beginning of the XPath expression indicates the root of the XML document.
Binding with Bind
The XForms model is 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 use bind attribute tobinding The <input> element:
<input bind="firstname"> <label>First Name</label> </input> <input bind="lastname"> <label>Last Name</label> </input>
Why are there two methods to bind input control elements to instance data?
When you start using XForms in complex applications, you will find that using bind for binding is a more flexible way to handle multiple forms and multiple instance models.
- Previous Page XForms Example
- Next Page XForms Input