Reputation: 173
how to add attribute for a element which also has restrictions for elements.
<xs:restriction base="xs:string">
<xs:enumeration value="Spring"/>
<xs:enumeration value="Summer"/>
<xs:enumeration value="Autumn"/>
<xs:enumeration value="Fall"/>
<xs:enumeration value="Winter"/>
</xs:restriction>
<xs:complexType>
<xs:attribute name="id"/>
</xs:complexType>
</xs:simpleType>
i want to set both attribute and restriction for to element. But using this way it's not working even with simpleContent & complexContent. So how to do it ?
Upvotes: 1
Views: 194
Reputation: 7279
You need to do this in two steps:
Like so:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:simpleType name="restrictedsimpletype">
<xs:restriction base="xs:string">
<xs:enumeration value="Spring"/>
<xs:enumeration value="Summer"/>
<xs:enumeration value="Autumn"/>
<xs:enumeration value="Fall"/>
<xs:enumeration value="Winter"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="restrictedwithattributes">
<xs:simpleContent>
<xs:extension base="restrictedsimpletype">
<xs:attribute name="id" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:element name="a" type="restrictedwithattributes"/>
</xs:schema>
Upvotes: 2