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

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

如何解决根据属性值允许或禁止元素

这与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 举报,一经查实,本站将立刻删除。