Skip to content
Hub Nexus

No author yetClaim it

Version 1Updated 2 min read

Support

Motivation

XML Schemas contain a large amount of data element constraint information other than just the data type. These restrictions on a specific data type are called "facets". Different data types have different types of facets. For example strings may have minimum and maximum length values and integers may have minimum and maximum numeric values.

This program demonstrates how XForms can validate a data set based on the facets within and XML Schema.

Warnings

Note: This program does not run under the FireFox 0.6 extension.

The X-Smiles browser was used to demonstrate this program.

Screen Image

This screen image was taken from the X-Smiles implementation of XForms.

Note that the second field is not at least three characters long so the field is invalid and the background it set to pink according to the CSS style for invalid fields.

XML Schema (schema.xsd)

Here is a simple XML Schema with four strings. The first one is only allowed to be two characters long. The second must have a minimum length of three characters. The third string must not be over five characters long and the fourth one must be between five and seven characters long to be valid.

xmlns:xs="http://www.w3.org/2001/XMLSchema">
name="Data">

A demonstration of XML Schema string facets.

name="string-length-2">

base="xs:string">
value="2"/>

name="string-min-3">

base="xs:string">
value="3"/>

name="string-max-5">

base="xs:string">
value="5"/>

name="string-5-7">

base="xs:string">
value="5"/>
value="7"/>

Sample Instance (instance.xml)

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="schema.xsd">
MN
abcd
abcd
abcdef

Sample Program

The following program loads both the XML Schema and initial instance data from two external files (schema.xsd and instance.xml). The initial data in this example is valid but you can change the data to test the validation.

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<head>
<title>Facet validation using X-Smiles.</title>
<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>
<xf:model id="test" schema="schema.xsd">
<xf:instance src="instance.xml" />
</xf:model>
</head>
<body>
<xf:group model="test" nodeset="/Data">
<p>
<xf:input ref="string-length-2" incremental="true">
<xf:label>Length exactly 2:</xf:label>
</xf:input>
</p>
<p>
<xf:input ref="string-min-3" incremental="true">
<xf:label>Length 3 or more:</xf:label>
</xf:input>
</p>
<p>
<xf:input ref="string-max-5" incremental="true">
<xf:label>Length 5 or less:</xf:label>
</xf:input>
</p>
<p>
<xf:input ref="string-5-7" incremental="true">
<xf:label>Length 5 to 7:</xf:label>
</xf:input>
</p>
</xf:group>
</body>
</html>

The two lines that load the XML Schema and instance data are:

id="test" schema="schema.xsd">
src="instance.xml" />

Also note that the input fields have the incremental attribute set to true. This allows character-by-character validation. The form is revalidated with each key stroke.

Where this page came from

This page was imported from Wikibooks. From “XForms” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.

Get each new page of

XForms

Following means one email when a page is added, nothing when a page changes.

Following means one email when a page is added, nothing when a page changes.

Comments

Spinner Logo

Next in XForms

CC BY-SA 4.0
XForms, SVG
CC BY-SA 4.0
But unlike most JavaScript functions, it will not be loaded into the browser until it is needed. ## Sample Program Here is an example of using the load element within an XForms trigger: First you will need a small JavaScript function to test like the following: <script type="text/javascript"> var My
CC BY-SA 4.0
XForms, Pie Chart
CC BY-SA 4.0
For a simple Pie Chart these might include: cht=p &chd=t:10,20,30,40,20 &chl=Amount|Indicator|Code|Date|Text &chs=400x300 Where: ** - is the Chart API's base URL The ampersand (&) separates parameters. **cht=p** is a code for the chart's type. For example p=2D Pie Chart and p3-3D Pie Chart **chd=t:1
CC BY-SA 4.0
Sending a **submit** will alter the Venn Diagram REST parameters. ### Screen Image of User Interface ![XForms User Interface for Venn Diagram]( XForms User Interface for Venn Diagram (Image: The original uploader was Dmccreary at English Wikibooks ., CC BY-SA 3.0) ### Output of Call to Google Charts
CC BY-SA 4.0
I also need to use CSS to clean up the markup. Price and Demand P Q Demand Input: Price = 100 Output: Quantity = 100 Adjust price by moving the slider. Note that as the input (price) changes. the quantity sold also changes.