How to use XML Schema to validate the xForms' field which bound to a XML file

0 views
Skip to first unread message

Gogo Liang

unread,
Aug 26, 2009, 3:47:00 AM8/26/09
to Ubiquity XForms Developers
Hi all.

I have got a question that when I try to use a XML Schema file to
validate the fields of the xml file. The xForms doesn't work. That is
it don't validate the fill-in text.

My code is:

XML File (test.xml):
<LeaveInfo>

<Topic></Topic>
<EmployeeName></EmployeeName>

</LeaveInfo>

XML Schema File (test.xsd):

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="LeaveInfo">
<xs:annotation>
<xs:documentation>The leave info</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>

<xs:element name="Topic">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="2"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

<xs:element name="EmployeeName">
<xs:simpleType>
<xs:restriction base="xs:string">
</xs:restriction>
</xs:simpleType>
</xs:element>

</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

xForm file:
…………
<style type="text/css">
@namespace xf url("http://www.w3.org/2002/xforms");
xf|input {
/* display: table-row; */
line-height: 2em;
}

xf|label {
/* display: table-cell; */
text-align: right;
font-family: Ariel, Helvetica, sans-serif;
font-weight: bold;
font-size: medium;
padding-right: 5px;
width: 130px;
}

*:required {
background-color: yellow;
}

*:invalid {
background-color: pink;
}
</style>
</head>

<body >
<xf:model schema="test.xsd">
<xf:instance id="LeaveData" src="test.xml"></xf:instance>
<xf:submitssion id="submitLeave"
action=""
method="post"/>
</xf:model>

<table width="600" border="1" align="center">
<tr>
<td>Title</td>
<td width="400px">
<xf:input ref="Topic" incremental="true">
<xf:alert>The 'Zip Code' failed to validate!</xf:alert>
</xf:input>
</td>
</tr>
<tr>
<td>EmployeeName</td>
<td>
<xf:input ref="EmployeeName" id ="employeename">
</xf:input>
</td>
…………

I want to know that why it does't work. Did I make any mistake? I will
be very happy that someone can do me a favor. Thank you in advance!
Reply all
Reply to author
Forward
0 new messages