XML schema: how to specify an attribute with a custom type of "simpleType"?

In my XML schema definition, I am trying to limit the attribute value to an integer from 0 to 100.

Regarding the example diagram below, I want the 'attr' attribute on the 'root' element to have this limitation. To do this, I define simpleType "Percentage" and set it to "type" attr.

However, my XML Schema Editor (VS 2008) puts the attribute up as having a problem: "The 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> 

+4
source share
1 answer

It looks like you are missing a namespace declaration in the root element of the schema:

 xmlns="http://testtttt" 

Therefore, the type reference is invalid.

+5
source

Source: https://habr.com/ru/post/1310241/


All Articles