The bounding element in xsd

I need to restrict the Age element in PersonalDetailsType so that it accepts only integer values. Changes should not be made in canonical.xsd. All changes must be made in Extn.xsd

I tried many ways but could not set a limit. So, I thought I came here. Below you can find the required XML, which 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>

XML Required

<EmployeeDetails>
    <AddressDetails>
        <Flat>123</Flat>
        <Place>India</Place>
        <PersonalInfo>
    <NameDeatils>
            <Name>Ram</Name>
            <Age>12</Age>
    </NameDeatils>
        </PersonalInfo>
    </AddressDetails>
</EmployeeDetails>
+4
source share
1 answer

You cannot redefine the type of Age to have a different type than the canonical one (see XSD: how to redefine the data type of a simple type, for example, from xs: string to xs: integer )

xs: redefine, AgeType " " (.. , min length = 1 ..), .

Age , xs: string, , xs: redefine , (. Is -, xsd: element?)

, Override:

xs: redefine xs: XML- 1.1

+1

All Articles