您可以使用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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...