ÍøÂçѧԺ w3popÉçÇø ÍøÂç×ÊÔ´ ITÐÂÎÅ

w3pop.com :: ÍøÂçѧԺ :: XForms :: XForms XPath

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

Íü¼ÇÃÜÂë? ×¢²á

XForms
XForms ½éÉÜ
XForms Ä£ÐÍ
XForms ÃüÃû¿Õ¼ä
XForms ʵÀý
XForms XPath
XForms ÊäÈë¿Ø¼þ
XForms Ñ¡Ôñ¿Ø¼þ
XForms Êý¾ÝÀàÐÍ
XForms ÊôÐÔ
XForms ÐÐΪ£¨Act..
XForms º¯Êý
Xforms Êý¾ÝÀàÐͲ..

XForms XPath


×÷Õß:w3pop.com ·­Òë/ÕûÀí:w3pop.com ·¢²¼:2007-04-29 ÐÞ¸Ä:2008-01-24 ä¯ÀÀ:1853 :: ::

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