开发者

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

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 开发者_JS百科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>


It looks like you are missing a namespace declaration on your schema root element:

xmlns="http://testtttt"

So the type reference is invalid.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜