Total members 11808 |It is currently Thu Dec 12, 2019 2:34 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





To put restrictions on the XML element values or XML attributes.XML elements restriction are called Facets.
1. Enumerations :
Only allow a set of values for your XML element.
Code:
<xs:element name="CustomColors">
<xs:simpleType>
  <xs:restriction base="xs:string">
    <xs:enumeration value="Red"/>
    <xs:enumeration value="Blue"/>
    <xs:enumeration value="Black"/>
  </xs:restriction>
</xs:simpleType>
</xs:element>


CustomColors values must have a value of these, (Red, Blue, & Black).


2. Patterns :
You limit your value to a series of letters and numbers .For example is the UUID.

Example on small letters patterns XSD element:

Code:
<xs:element name="small_letters">
<xs:simpleType>
  <xs:restriction base="xs:string">
    <xs:pattern value="[a-z]"/>
  </xs:restriction>
</xs:simpleType>
</xs:element>

Example on numbers only XSD element:
Code:
<xs:element name="numbers_only">
<xs:simpleType>
  <xs:restriction base="xs:string">
    <xs:pattern value="[0-9]"/>
  </xs:restriction>
</xs:simpleType>
</xs:element>







Universally Unique Identifier (UUID) XSD example:
Code:
     <element name="UUID" minOccurs="1">
               <simpleType>
                  <restriction base="ID">
                     <pattern
                        value="[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}">
                     </pattern>
                  </restriction>
               </simpleType>
            </element>


3. Numbers Range :
You can define the value range of an element. In the following example, the colorindex element can take value between (0-120).
Code:
<xs:element name="colorindex">
<xs:simpleType>
  <xs:restriction base="xs:integer">
    <xs:minInclusive value="0"/>
    <xs:maxInclusive value="120"/>
  </xs:restriction>
</xs:simpleType>
</xs:element>



4. Whitespaces :


You can leave the white spaces with no changes. preserve means no change.

Code:
<xs:element name="StudentName">
<xs:simpleType>
  <xs:restriction base="xs:string">
    <xs:whiteSpace value="preserve"/>
  </xs:restriction>
</xs:simpleType>
</xs:element>


You can use replaceĀ value instead of preserve.This replace all space characters like (tabs ,line feeds ,and carriage return )with spaces.


Code:
<xs:element name="StudentName">
<xs:simpleType>
  <xs:restriction base="xs:string">
    <xs:whiteSpace value="replace"/>
  </xs:restriction>
</xs:simpleType>
</xs:element>


You can use collapseĀ to remove large spaces to one space.
Code:
<xs:element name="StudentName">
<xs:simpleType>
  <xs:restriction base="xs:string">
    <xs:whiteSpace value="collapse
"/>
  </xs:restriction>
</xs:simpleType>
</xs:element>


5. Values lengths:
You can set the length of element value; your value must equal the length restriction.

Code:
<xs:element name="username">
<xs:simpleType>
  <xs:restriction base="xs:string">
    <xs:length value="8"/>
  </xs:restriction>
</xs:simpleType>
</xs:element>

You can define It with other way, minLength and manLength values.
Code:
<xs:element name="password">
<xs:simpleType>
  <xs:restriction base="xs:string">
    <xs:minLength value="5"/>
    <xs:maxLength value="8"/>
  </xs:restriction>
</xs:simpleType>
</xs:element>





_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : lesson4:XSD Restrictions
 restrictions on the values of each case of a switch     -  



Topic Tags

XSD Elements






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com