Tip: apply XMLSchemaStandardTypeLibrary to simplify development application mode definition simplification routine verification XML verification allows you to create complex rules to define acceptable data. However, if you do not apply these rules, they are useless. In
Tip: simplified development of XML Schema Standard Type Library
Simplified routine verification of application mode definition
XML verification allows you to create complex rules to define acceptable data. However, if you do not apply these rules, they are useless. In this article, you will learn how to use the XML Schema Standard Type Library to simplify the process of obtaining structured data (such as email addresses and phone numbers.
This article assumes that you are familiar with XML and have at least a certain degree of understanding of XML Schema. The example in this article will apply XForms, but do not force requests to understand XForms. (If you want to run the example, you can download the XForms extension for Firefox. )
Validate XML or ensure that certain Type-based constraints are inherent in the language; Document Type Definitions is part of the XML specification. Soon afterwards, the demand for higher mobility and higher efficiency gradually became apparent, resulting in an XML Schema. XML Schema allows you to create many specially designated definitions. You can specify that an element must contain a specific number of additional elements, or that an attribute must contain a datetime value. The text conforms to a certain pattern, or any other structure.
For example, consider the following XForms (see listing 1 ).
List 1. Basic forms
Xmlns: xforms = 'http: // www.w3.org/2002/xforms'
Xmlns: xsd = 'http: // www.w3.org/2001/XMLSchema'>
Contact Form
Action = '.'/>
Contact information
Name:
Email:
Phone:
Submit
This form is very simple, just look for the user's name, email address and phone number, as shown in 1.
Figure 1. form
In this example, it is helpful to bind an email or phone number entry to a valid email or phone number-or at least to an accurate one. To do this, you need to add a mode to the document (see listing 2 ).
List 2. add mode
...
...
You can then add events to notify users when the entries are invalid (see application methods in source code ).
Note that the email and phone number definitions do not have any additional types. The reason is that most programmers are reluctant to roll in the check type. Email addresses have a variety of patterns, but there is a scale pattern. Similarly, there are many telephone numbers, such as "with area code", "Without area code", and "with location code", which do not contain country area codes.
Who is willing to do all these jobs? I don't want. Fortunately, there are common types of libraries with phone numbers or email addresses. You can download XML schema standard type library from the http://www.codesynthesis.com/projects/xsstl. Import the library to the mode by importing the correct namespace and document (see figure 3 ).
Listing 3. import mode definition
Xmlns: ev = 'http: // www.w3.org/2001/xml-events'
Xmlns: xforms = 'http: // www.w3.org/2002/xforms'
Xmlns: xsd = 'http: // www.w3.org/2001/XMLSchema'
Xmlns: stl = 'http: // www.codesynthesis.com/xmlns/xsstl'>
Contact Form
Xmlns: stl = 'http: // www.codesynthesis.com/xmlns/xsstl'>
Namespace = 'http: // www.codesynthesis.com/xmlns/xsstl'
SchemaLocation = 'xsstl. xsd '/>