XML Schema: How to specify an attribute with a custom 'simpleType' type?

Posted by mackenir on Stack Overflow See other posts from Stack Overflow or by mackenir
Published on 2010-05-19T13:31:30Z Indexed on 2010/05/19 13:40 UTC
Read the original article Hit count: 278

Filed under:
|
|

In my XML schema definition, I'm trying to restrict the value of an attribute to be an integer between 0 and 100.

With reference to the sample schema below, I want attribute 'attr' on element 'root' to have this restriction. To achieve this I define a simpleType 'Percentage' and set this as the 'type' of 'attr'.

However, my XML schema editor (VS 2008) flags the attribute up as having a problem: "Type 'Percentage' is not declared or is not a simple type".

<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" id="test" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://testtttt">
  <xs:simpleType name="Percentage">
    <xs:restriction base="xs:integer">
      <xs:minInclusive value="0"/>
      <xs:maxInclusive value="100"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:element name="root">
    <xs:complexType>
      <xs:attribute name="attr" type="Percentage" use="optional" />
    </xs:complexType>
  </xs:element>

© Stack Overflow or respective owner

Related posts about xml-schema

Related posts about xsd