具有固定属性的固定元素的XML模式? [英] XML Schema for a fixed element with a fixed attribute?

查看:100
本文介绍了具有固定属性的固定元素的XML模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是

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

其中:

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

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

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>

推荐答案

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

这篇关于具有固定属性的固定元素的XML模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆