Total members 9951 | Gratitudes |It is currently Sat Feb 11, 2012 9:55 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Article
 Article subject: lesson4:XSD Restrictions
PostPosted: Wed Feb 25, 2009 12:38 am 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2103
Location: Earth
Has thanked: 39 time
Have thanks: 56 time

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>


_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 restrictions on the values of each case of a switch  Java  AskBot  1

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Article | Next Article 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team