根据属性值允许或禁止元素

问题描述

这与37071177有关,但不完全相同。

我可以使用一个属性如下的容器吗?

<question type="select">
  <text>This is the text</text>
  <selection points="1">This is a choice</selection>
  <selection points="20">This is a different choice</selection>
</question>

仅在父@type属性的值为“ select”时才出现选择项,而在“ yes / no”或其他情况下不存在选择项吗?我以为我可以使用来做到这一点,但是您不能在其中放置断言...

我发现lots of examples是使用共约束来基于另一个属性的存在或值来限制一个属性的存在,而不是用来限制 的存在(或(可能是maxOccurs)基于属性 value

<!-- this is a question - it might have one or more selections depending on its type -->
<xs:complexType name="questionType">
  <xs:sequence>
    <xs:element name="topic" maxOccurs="1" minOccurs="1" type="xs:string" />
    <xs:element name="text" maxOccurs="1" minOccurs="1"></xs:element>
    <xs:element name="selection" maxOccurs="unbounded" minOccurs="0" type="selectionType" />
  </xs:sequence>
    <xs:attribute name="id" type="xs:string" use="required" />
    <xs:attribute name="type" use="required">
      <xs:simpleType>
        <xs:restriction base="xs:string">
        <xs:enumeration value="yesno" />
        <xs:enumeration value="select" />
      </xs:restriction>
    </xs:simpleType>
  </xs:attribute>
</xs:complexType>

<!-- if the type of the question is 'selection' it may have one or more of these -->
<xs:complexType name="selectionType">
  <xs:simpleContent>
    <xs:extension base="xs:string">
      <xs:attribute name="points" type="xs:int" use="required" />
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

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