Jump to content
Sign in to follow this  
shiyanderu

How to define restrictions on an attribute

Recommended Posts

Hello again,I have a custom date attribute that I'd like to add as "required" on an element. I would like this date attribute to follow the mm/dd/yyyy format, and so I would like to put restrictions on it.W3Schools has mentioned that restrictions can be added to both elements and attributes, but I have yet to see any example of a restriction being set on an attribute. If anyone could help me set a restriction on an attribute to conform to mm/dd/yyyy, I would be most grateful.Code's below :-)<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string" maxOccurs="unbounded"/> <xs:element name="from" type="xs:string"/> <xs:element name="subject"> <xs:complexType> <xs:attribute name="date" type="xs:date" use="required" form="qualified"/> </xs:complexType> </xs:element> <xs:element name="body"> <xs:complexType> <xs:sequence> <xs:any minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element></xs:schema>

Share this post


Link to post
Share on other sites
<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">	<xs:element name="note">		<xs:complexType>			<xs:sequence>				<xs:element name="to" type="xs:string" maxOccurs="unbounded"/>				<xs:element name="from" type="xs:string"/>				<xs:element name="subject">					<xs:complexType>						<xs:attribute name="date" type="xs:date" use="required" form="qualified"/>					</xs:complexType>				</xs:element>				<xs:element name="body">					<xs:complexType>						<xs:sequence>							<xs:any minOccurs="0"/>						</xs:sequence>					</xs:complexType>				</xs:element>			</xs:sequence>		</xs:complexType>	</xs:element></xs:schema>

Share this post


Link to post
Share on other sites

It is possible, instead of this line:

<xs:attribute name="date" type="xs:date" use="required" form="qualified"/>

you need to have something like this:

<xs:attribute name="date" type="carType" use="required" form="qualified"/>

then add this section somewhere:

<xs:simpleType name="carType">  <xs:restriction base="xs:string">	<xs:enumeration value="Audi"/>	<xs:enumeration value="Golf"/>	<xs:enumeration value="BMW"/>  </xs:restriction></xs:simpleType>

Obviously carType is not what you need, but it's an example lifted right off the w3schools website...http://www.w3schools.com/schema/schema_facets.aspCraig.[edit]oh man! sorry i didn't realise how old this topic was... sorry the assistance is so late in coming, i presume you'd have sorted it by now[/edit]

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...