微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

您可以使用xs:assert和继承吗

如何解决您可以使用xs:assert和继承吗

我正在使用继承来定义一个具有一些属性的基本类型questionBase和一组问题扩展类型(子类)。我开始时没有基类,并注意到几个元素和属性的重复。效果很好,但是我很难弄清楚在引入xs:complexContent和xs:Extension之前存在的“最小必须大于或等于最小”断言。

我将在尝试的地方下方显示

我只想在子类中使用此限制,因为其他问题类型没有最小值和最大值。我得到的错误是:

错误:(78,46)s4s-elt-invalid-content.1:的内容 'rangeQuestionType'无效。元素“断言”无效, 放错位置或发生得太频繁。

Example 14-15 in this book使我认为它应该在这里工作。

我正在使用Android Studio / IntelliJ进行验证。我也用this online validation tester尝试过,但它也给了我同样的错误。我还尝试了上面引用的示例14-15,但它也不起作用-那本书不正确吗?

    <xs:complexType name="questionBase">
        <xs:sequence>
            <xs:element name="topic" maxOccurs="1" minOccurs="1" type="xs:string" />
            <xs:element name="text" maxOccurs="1" minOccurs="1"></xs:element>
        </xs:sequence>
        <xs:attribute name="id" type="xs:string" use="required" />
    </xs:complexType>

    <!-- A range question has a min and max score,for example 1-5 or 0-100 -->
    <xs:complexType name="rangeQuestionType">
        <xs:complexContent>
            <xs:extension base="questionBase">
                <xs:sequence>
                    <xs:element name="note" maxOccurs="1" minOccurs="0"></xs:element>
                    <xs:element name="score" maxOccurs="1" minOccurs="0" type="scoreType" />
                </xs:sequence>
                <xs:attribute name="min" use="required">
                    <xs:simpleType>
                        <xs:restriction base="xs:int">
                            <xs:minInclusive value="0" />
                        </xs:restriction>
                    </xs:simpleType>
                </xs:attribute>

                <!-- the only restriction is that min must be less than or equal to max -->
                <xs:attribute name="max" use="required">
                    <xs:simpleType>
                        <xs:restriction base="xs:int">
                            <xs:minInclusive value="1" />
                        </xs:restriction>
                    </xs:simpleType>
                </xs:attribute>

<!-- placing it here gives "Element 'assert' is misplaced or occurs too often -->
<!-- ... but this is where I think it belongs ... -->
                <xs:assert test="@min le @max" />
            </xs:extension>
<!-- placing it here also gives "Element 'assert' is misplaced or occurs too often -->
        </xs:complexContent>
<!-- placing it here also gives "Element 'assert' is misplaced or occurs too often -->
    </xs:complexType>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。