I need to restrict the Age element in PersonalDetailsType, such that it accepts only integer values. Changes should not be made in canonical.xsd. All the modification has to be made in Extn.xsd
I tried many ways, but not able to put restriction.So, thought to come here.At the bottom you can find the required XML that should obey Extn.xsd.
Thanks in advance..
canonical.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://www.example.org/cononical"
xmlns:con="http://www.example.org/cononical"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Employees">
<xs:complexType>
<xs:sequence>
<xs:element ref="NameDeatils"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="NameDeatils" type="con:PersonalDetailsType"/>
<xs:complexType name ="PersonalDetailsType" >
<xs:sequence >
<xs:element type="xs:string" name="Name"/>
<xs:element ref="con:Age"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Age" type="con:AgeType"></xs:element>
<xs:simpleType name="AgeType">
<xs:restriction base="con:BaseType">
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="BaseType">
<xs:restriction base="xs:string">
</xs:restriction>
</xs:simpleType>
</xs:schema>
Extn.xsd
<xs:schema attributeFormDefault="unqualified"
targetNamespace="http://www.example.org/cononicalExtn"
xmlns:conExtn="http://www.example.org/cononicalExtn"
xmlns:con="http://www.example.org/cononical"
elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://www.example.org/cononical" schemaLocation ="canonical.xsd"/>
<xs:element name="EmployeeDetails">
<xs:complexType>
<xs:sequence>
<xs:element name="AddressDetails">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:short" name="Flat"/>
<xs:element type="xs:string" name="Place"/>
<xs:element ref ="conExtn:PersonalInfo"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="PersonalInfoType">
<xs:sequence>
<xs:element ref ="con: NameDeatils” />
</xs:sequence>
</xs:complexType>
<xs:element name="PersonalInfo" type="conExtn:PersonalInfoType" />
</xs:schema>
Required XML
<EmployeeDetails>
<AddressDetails>
<Flat>123</Flat>
<Place>India</Place>
<PersonalInfo>
<NameDeatils>
<Name>Ram</Name>
<Age>12</Age>
</NameDeatils>
</PersonalInfo>
</AddressDetails>
</EmployeeDetails>