| Refresh | Home EGTry.com

user defined type with constraining


xml attribute with constraining

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="test.xsd">

  <element1 
    int1to10="10"
    >
    Text inside element
  </element1>

</root>

schema

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema">
   <xs:element name = "root">
      <xs:complexType>
        <xs:sequence>

          <xs:element name="element1" >
             <xs:complexType>
               <xs:simpleContent>
                 <xs:extension base="xs:string">
	                 <xs:attribute name="int1to10" type="int1" use="required"/>
                 </xs:extension>
               </xs:simpleContent>
             </xs:complexType>
          </xs:element>


        </xs:sequence>
      </xs:complexType>
   </xs:element>

   <xs:simpleType name="int1">
    <xs:restriction base="xs:integer">
      <xs:minInclusive value="1"  />
      <xs:maxInclusive value="10" />
    </xs:restriction> 
   </xs:simpleType>

</xs:schema>