XML Schema for a fixed element with a fixed attribute?

让人想犯罪 __ 提交于 2019-12-23 09:31:43

问题


What would be the correct XML Schema 1.0 declaration for a

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

where:

  1. The xml:lang attribute is compulsory
  2. The value "en" is fixed and compulsory
  3. The content of notice is simple text.
  4. The content of notice is fixed (as above) and compulsory?

My best (but wrong) effort is the following fragment:

<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>

回答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>


来源:https://stackoverflow.com/questions/9695635/xml-schema-for-a-fixed-element-with-a-fixed-attribute

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!