【问题标题】:Adding both restriction and attribute(s) to complexType向 complexType 添加限制和属性
【发布时间】:2011-04-04 18:40:00
【问题描述】:

对于带有type="xs:int" 的简单元素,我想同时添加一个限制和一些属性。但是,我看到它完成的唯一方法是分两步:

  1. 声明一个命名(全局)类型并将所有限制放在命名类型中

  2. 引用<xs:extension>base中的命名类型并将属性添加到扩展节点。

如果我可以避免声明全局命名类型,因为模式是动态生成的,并且在本地指定所有限制会更简洁。例如。像这样:

<xs:complexType>
  <xs:simpleContent>
    <xs:extension base="xs:int">
      <xs:minInclusive>2</xs:minInclusive>
      <xs:attribute name="myAttribute" type="xs:boolean" />
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>

或者在字符串类型的情况下:

<xs:complexType>
  <xs:simpleContent>
    <xs:extension base="xs:string">
      <xs:enumeration Value="FOO" />
      <xs:enumeration Value="BAR" />
      <xs:enumeration Value="BAZ" />
      <xs:attribute name="myAttribute" type="xs:boolean" />
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>

不幸的是,这样的“组合”声明似乎是不允许的。

【问题讨论】:

  • 不得不承认,我仍然对 SO 接受答案的依据感到有些困惑 :(

标签: xml xsd structure


【解决方案1】:

【讨论】:

  • 我看到了帖子,但认为它与我的问题不符。仔细一看,我可以看到它确实如此。谢谢!
【解决方案2】:

很遗憾,这是不可能的。您当前的方式(使用单独的类型)是要走的路。此类请求是在before 提出的(尽管可能不在 SO 中)。

【讨论】:

    猜你喜欢
    • 2019-07-28
    • 1970-01-01
    • 2016-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-06
    • 1970-01-01
    • 2018-10-28
    相关资源
    最近更新 更多