【问题标题】:XML Schema for a fixed element with a fixed attribute?具有固定属性的固定元素的 XML 模式?
【发布时间】:2012-03-14 03:45:39
【问题描述】:

什么是正确的 XML Schema 1.0 声明

<notice xml:lang="en">Banana banana banana</notice>

地点:

  1. xml:lang 属性是强制性的
  2. 值“en”是固定且强制的
  3. 通知内容为简单文本。
  4. 通知的内容是固定的(如上)和强制性的?

我最好的(但错误的)努力是以下片段:

<xs:element name="notice" use="required" fixed="Banana banana banana">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension>
        <xs:attribute ref="xml:lang" use="required" fixed="en"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

【问题讨论】:

    标签: xsd xsd-1.0


    【解决方案1】:
    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:import namespace="http://www.w3.org/XML/1998/namespace" />
      <xs:element name="notice" type="notice"/>
        <xs:complexType name="notice">
          <xs:simpleContent>
            <xs:extension base="CONTENT">
              <xs:attribute ref="xml:lang" use="required" fixed="en"/>
            </xs:extension>
          </xs:simpleContent>
        </xs:complexType>
      <xs:simpleType name="CONTENT">
        <xs:restriction base="xs:string">
          <xs:enumeration value="Banana banana banana"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:schema>
    

    【讨论】:

    • 谢谢。唯一的问题是它没有将“en”强制为 xml:lang 。我认为这可以通过在解决方案的 xs:attribute 节点中添加一个 fixed="en" 属性来实现。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多