Home arrow XML arrow Page 4 - Designing Your own XML Schema: Constraining with Restrictions
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Designing Your own XML Schema: Constraining with Restrictions - Restricting lengths in XML Schema
(Page 4 of 6 )

Let us consider that we would like to have any employee name restricted to fifty characters, with a minimum of four characters.  The following complete schema would accomplish this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 elementFormDefault="qualified" attributeFormDefault=
"unqualified">
      <xs:element name="Employees">
            <xs:annotation>
                  <xs:documentation>Contains All Employee information</xs:documentation>
            </xs:annotation>
            <xs:complexType>
                  <xs:sequence>
                        <xs:element name="Employee" maxOccurs="unbounded">
                              <xs:complexType>
                                    <xs:sequence>
                                          <xs:element name="Name">
                                                <xs:simpleType>
                                                      <xs:restriction base="xs:string">
                                                            <xs:maxLength value="50" />
                                                            <xs:minLength value="4" />
                                                      </xs:restriction>
                                                </xs:simpleType>
                                          </xs:element>
                                    </xs:sequence>
                                    <xs:attribute name="ID" type="xs:string" use="required" />
                              </xs:complexType>
                        </xs:element>
                  </xs:sequence>
            </xs:complexType>
      </xs:element>
</xs:schema>



You need to observe the following fragment within the above complete schema, which actually does the restriction:

<xs:element name="Name">
      <xs:simpleType>
            <xs:restriction base="xs:string">
                  <xs:maxLength value="50" />
                  <xs:minLength value="4" />
            </xs:restriction>
      </xs:simpleType>
</xs:element>

The most important parts are the “maxLength” and “minLength” which handle our restriction.


blog comments powered by Disqus
XML ARTICLES

- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- Datatypes and More in RELAX NG
- Providing Options in RELAX NG
- An Introduction to RELAX NG
- Path, Predicates, and XQuery
- Using Predicates with XQuery
- Navigating Input Documents Using Paths
- XML Basics
- Introduction to XPath
- Simple Web Syndication with RSS 2.0
- Java UI Design with an IDE

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials