当前位置: 首页 > 网络学院 > XML相关教程 > XForms > XForms XPath

XForms
XForms 介绍
XForms 模型
XForms 命名空间
XForms 实例
XForms XPath
XForms 输入控件
XForms 选择控件
XForms 数据类型
XForms 属性
XForms 行为(Actions)
XForms 函数
Xforms 数据类型参考

XForms XPath


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 561 ::
收藏到网摘: n/a

XForms uses XPath to address data. This is called binding."
XForms用XPath对数据进行寻址,这称之为绑定(binging)。


XForms Binding
XForms绑定

XForms uses two sections to define data: The XForms model and the XForms user interface.
XForms 使用两个部分来定义数据:XForms 模型和 XForms 用户界面。

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 模型是针对数据的一个 XML 模板(实例),而 XForms 用户界面是对数据输入和显示的描述。

XForms uses XPath to define the connection between the two sections. This is called binding.
XForms 使用 XPath 来定义这个两个部分的连接。这被称为绑定(binding)


XPath

XPath is a W3C standard syntax for defining parts of XML documents.
XPath 用于定义 XML 文档的各部分的 W3C 标准语法。

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.
XPath 使用路径表达式来标示 XML 文档中的节点。这些表达式与您在计算机系统中看到的文件路径表达式非常类似。

This XPath expression:
XPath表达式:

/person/fname

addresses the fname node in the XML document:
传送XML文档中的fname节点:

<person>
<fname>Hege</fname>

<lname>Refsnes</lname>
</person>

Learn more about XPath in our XPath tutorial
在我们的XPath教程里了解更多内容。


Binding Using Ref
使用 Ref 绑定

With an XForms model instance like this:
XForms 模型是这样的:

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

The XForms user interface can bind <input> elements using the ref attribute:
XForms 用户界面可使用 ref 属性来捆绑 <input> 元素:

<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.
上面例子中的 ref="name/fname" 属性是一个指向实例模型中 <fname> 元素的 XPath 表达式。它可将输入域捆绑到正从表单收集数据的 XML 文档(实例)中的 <fname> 元素。

The XForms user interface could also use a reference like this:
XForms 用户界面也可以使用引用:

<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.
在上面的例子中,XPath 表达式起始部位的正斜杠 (/) 指示 XML 文档的根。


Binding Using Bind
使用 Bind 绑定

With an XForms model instance like this:
XForms 模型是这样的:

<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:
XForms 用户界面可使用 bind 属性来捆绑 <input> 元素:

<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.
怎么说呢,当您在复杂的应用程序中开始使用 XForms 时,您会发现,使用 bind 进行绑定是一种更灵活的处理多重表单和多重实例模型的方法。

评论 (0) All

登陆 | 还没注册?