I have a question regarding adding restriction in my xml schema(xsd). I have a complex-type like:
<xsd:complexType name="xxx"> <xsd:attribute/> ..... </xsd:complexType>
I have many attributes in this complex-type, and few of them are of string type. Now I want those string type attributes to be restricted to y no. of chars, how do I add this restriction?
Thanks! -Ankush
Definition and Usage The complexType element defines a complex type. A complex type element is an XML element that contains other elements and/or attributes.
The minOccurs attribute specifies the minimum number of times that the element can occur. It can have a value of 0 or any positive integer. The maxOccurs attribute specifies the maximum number of times that the element can occur.
XSD elements can be of type simpleType , complexType , or anyType . An element of type simpleType contains only text. It cannot have attributes and elements. An element of type complexType can contain text, elements, and attributes.
You need to create a simple type like so:
<xs:simpleType name="LimitedString"> <xs:restriction base="xs:string"> <xs:maxLength value="50" /> </xs:restriction> </xs:simpleType>
and then use this new type in your schema:
<xs:complexType name="test"> <xs:sequence> <xs:element name="abc" type="xs:String" /> </xs:sequence> <xs:attribute type="LimitedString" name="myattr" /> </xs:complexType>
Marc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With