XForms 模型支持 XML Schema 數(shù)據(jù)類型。
XForms 數(shù)據(jù)類型
XML Schema 數(shù)據(jù)類型
XForms 模型支持 XML Schema 數(shù)據(jù)類型。此特性使 XForms 處理器有能力為了確保輸入值的正確性對數(shù)據(jù)進行檢查。
您可以在我們的 XML Schema 教程 中學習更多有關(guān) XML Schema 的指示。
如需使用 XML Schema 數(shù)據(jù)類型,您必須向命名空間聲明添加 XML Schema 命名空間,就像這樣:
<html xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
在添加 XML Schema 命名空間之后,您可以向 XForms 的 instance 元素添加 type 屬性,就像這樣:
<xf:instance> <person xmlns=""> <fname xsi:type="xsd:string"/> <lname xsi:type="xsd:string"/> <born xsi:type="xsd:date>"/> <size xsi:type="xsd:integer"/> </person> </xf:instance>
XForms 支持除下列類型以外的所有 XML Schema 數(shù)據(jù)類型:
- duration
- ENTITY
- ENTITIES
- NOTATION
如需完整的 XForms 數(shù)據(jù)類型參考,請訪問:
完整的 XForms 數(shù)據(jù)類型參考手冊
Try it yourself
數(shù)據(jù)類型綁定
在 XForms 中,您也可以使用 <bind> 元素來對實例數(shù)據(jù)與數(shù)據(jù)類型進行關(guān)聯(lián):
<xf:bind nodeset="/person/size" type="xsd:integer"/>