You have to define a simpleType and define the restrictions on the
values for the attribute in the type definition as in the schema below.
Check out the <simpleType> definition that defines a new type based on
xs:integer but with the <restriction> that the maximum value of a valid
instance of the type is 99.
The attribute definition for the ID attribute uses that type to enforce
the restrictions on your ID
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace ="urn:myname " xmlns:tns="urn: myname"
elementFormDefa ult="qualified" >
<xs:simpleTyp e name="myidtype" >
<xs:restricti on base="xs:intege r">
<xs:maxExclusiv e value="100" />
</xs:restriction>
</xs:simpleType>
<xs:element name="Book">
<xs:complexType >
<xs:sequence>
<xs:element name="Name" type="xs:string "/>
<xs:element name="Comments" type="xs:string "/>
</xs:sequence>
<xs:attribute name="ID" type="tns:myidt ype" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
There are a number of other possibilities for the <restrictions > which
you can look up in a good discussion of XML Schema or in the XML schema
spec at [0]
HTH,
Christoph Schittko
MS MVP XML
http://weblogs.asp.net/cschittko
[0]
http://www.w3.org/XML/Schema.html#dev
_______________ _______________ __
From: Shailendra Batham [mailto:sh****** **@sitesystems. com]
Posted At: Monday, November 15, 2004 4:05 PM
Posted To: microsoft.publi c.dotnet.xml
Conversation: Restrictions on Attributes in XML Schema.
Subject: Restrictions on Attributes in XML Schema.
Hello Gurus,
I want to put some restrictions on my attribute tag in my XML Schema,
anyone out there have any idea how to do that.
here is my XML and the XML Schema
<?xml version="1.0" encoding="utf-8"?>
<Book ID="1000000000" >
<Name>XML Basic</Name>
<Comments>Whate ver</Comments>
</Book>
</Survey>
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Book">
<xs:complexType >
<xs:sequence>
<xs:element name="Name" type="xs:string "/>
<xs:element name="Comments" type="xs:string "/>
</xs:sequence>
<xs:attribute name="ID" type="xs:intege r" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
I want to put some restrictions on the ID, eg, the ID cannot be more
than 10000.......... . so how do i add restrictions to attributes, I
already know restrictions for elements but that is not helping me for
attributes.
help is appreciated,
Thanks
shailendra batham