0

I have this line of code

<floatOutput id="2">myValue</floatOutput>

I want to put an restriction on "myvalue" that it should be between -50 and 50. I have tried many options but i don't know how to use extension and restriction toghether. Can someone answer please?

Kenney
  • 9,003
  • 15
  • 21
Usman Khan
  • 147
  • 15
  • this is the line of code : myValue – Usman Khan Feb 06 '16 at 13:48
  • 1
    You don't need extension, just restriction with a `base` attribute of xsd:int/integer. See [this question](http://stackoverflow.com/questions/15486246/xsd-default-integer-value-range) for an example. – Kenney Feb 06 '16 at 13:54

1 Answers1

0

You will need both an extension (since you have the attribute id) and a restriction (since you have the constraint on the content of floatOutput). One approach that I know of is to create a simple type with the constraint and then extend this type with the attribute. So something like the following.

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xs:simpleType name="floatOutputType">  
      <xs:restriction base="xs:integer">  
          <xs:minInclusive value="-50"/>  
          <xs:maxInclusive value="50"/>  
      </xs:restriction>  
  </xs:simpleType>

  <xs:element name="floatOutput">  
    <xs:complexType>  
      <xs:simpleContent>  
        <xs:extension base="floatOutputType">  
          <xs:attribute name="id" type="xs:byte" use="required"/>  
        </xs:extension>  
      </xs:simpleContent>  
    </xs:complexType>  
  </xs:element>
</xs:schema>
Mikkelbu
  • 135
  • 1
  • 9