| <?xml version="1.0" encoding="UTF-8"?> |
| <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.0//EN" "../../dtd/document-v10.dtd"> |
| |
| <document> |
| <header> |
| <title>XMLForm's How-To Step 2</title> |
| |
| <authors> |
| <person name="Heidi Brannan" |
| email="heidi@wkwyw.net" /> |
| </authors> |
| </header> |
| |
| <body> |
| <s1 title="Step 2: Validation"> |
| <fixme author="DS">Who is we? The "royal" we? ;-). Shifting to |
| we, in the middle of this doc, is confusing. Give a reason or two why |
| it's helpful to validate...</fixme> |
| |
| <p>The next step, validation, is optional. You do not have to validate |
| your forms. Because we believe it's very easy to do so, we will do |
| so here.</p> |
| |
| <fixme author="DS">Below you write: if these are left empty. If you |
| leave *what* empty? The name, values, or both?</fixme> |
| |
| <p>In the sitemap there are two parameters, xmlform-validator-schema and |
| xmlform-validator-schema-ns. If you leave them empty, then no validation |
| will be carried out. xmlform-validator-schema contains the name of the |
| xml schema file we are using. xmlform-validator-schema-ns is the |
| validator namespace we are using. Here is how the two parameters are |
| referenced in the sitemap.</p> |
| |
| <source> |
| <![CDATA[ |
| <map:parameter name="xmlform-validator-schema-ns" |
| value="http://www.ascc.net/xml/schematron"/> |
| |
| <map:parameter name="xmlform-validator-schema" |
| value="schematron/wizard-xmlform-sch-report.xml"/> |
| ]]> |
| </source> |
| |
| <p>Copy the "howto-xmlform-sch-report.xml," and place it in the |
| folder src\blocks\scratchpad\samples\xmlform\howto\schematron.</p> |
| |
| <fixme author="DS">Sometimes it's useful to show the dtd for the |
| schema.</fixme> |
| |
| <p>The schema shown below is simple. It validates only the |
| registration.xml page. The phase element includes information concerning |
| the xml page to be validated. The id attribute contains the page name. |
| The phase element contains an active element whose pattern attribute |
| matches up to the pattern element below. Each pattern can contain one or |
| more rule elements. Each rule element has a context attribute which maps |
| to a javaBean value, for example userName. Nested inside the rule |
| element is one or more assert element. Each assert element contains a |
| test attribute. The value of test can be used to check certain criteria, |
| for example, if a passed value is more than seven characters long. |
| Nested between the beginning and closing assert tags is an error message |
| text to be displayed when the test fails.</p> |
| |
| <source> |
| <![CDATA[ |
| <?xml version="1.0" ?> |
| |
| <schema ns="http://xml.apache.cocoon/xmlform" |
| xmlns="http://www.ascc.net/xml/schematron"> |
| |
| <title>Schema for the XML Form example</title> |
| |
| <phase id="registration"> |
| <p>For user identity information.</p> |
| <active pattern="reg"/> |
| </phase> |
| |
| <phase id="confirm"> |
| <p>For final total validation and tracking |
| some tricky problems.</p> |
| <active pattern="reg" /> |
| </phase> |
| |
| <pattern name="User Info Validation Pattern" id="reg"> |
| <rule context="/userName"> |
| <assert test="string-length(.) > 7"> |
| Username should be at least 8 characters. |
| </assert> |
| <assert test="string-length(.) < 20"> |
| Username should be less than 20 characters. |
| </assert> |
| </rule> |
| <rule context="/password"> |
| <assert test="string-length(.) > 7"> |
| Password should be at least 8 characters. |
| </assert> |
| <assert test="string-length(.) < 20"> |
| Password should be less than 20 characters. |
| </assert> |
| </rule> |
| <rule context="/email"> |
| <assert test="contains( string(.),'@')"> |
| Email format is invalid. |
| </assert> |
| </rule> |
| </pattern> |
| </schema> |
| ]]> |
| </source> |
| |
| <p>Now you are ready for <link href="howto-xmlform-wizard-3.html">Step |
| 3: Form instance model</link></p> |
| </s1> |
| </body> |
| </document> |