需要 XSD 中混合内容的示例 [英] Need example of mixed content in XSD

查看:24
本文介绍了需要 XSD 中混合内容的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 HTML 代码:

I have this HTML code:

<description>This is an <a href="example.htm">example</a> <it>text </it>!</description>

对于此代码,我必须创建一个 XSD.

For this code, I have to create an XSD.

我的尝试是用 xs:alla 标签和 it 标签创建一个元素.但是如何在 xs:all 中创建简单的文本?我用字符串元素试过了,但这当然是错误的,因为它是一个元素.但如果我使用 any 元素,它也是一个元素.如何在 a 和 it 标签中创建这个简单的文本?

My try was to create an element with xs:all for a tag and it tag. But how can I create the simple text within the xs:all? I tried it with an string element, but this is of course wrong, because it is an element. But also if I am using an any element, it is an element. How can I create this simple text within the a and it tags?

<xs:element name="description" minOccurs="0">
     <xs:complexType>
         <xs:all>
          <xs:element name="a">
                <xs:complexType>
                  <xs:attribute name="href" type="xs:string" />
                 </xs:complexType>
               </xs:element>
          <xs:element name="it" type="xs:string" />
          <xs:element name="text" type="xs:string" />
        </xs:all>
    </xs:complexType>
  </xs:element>

推荐答案

允许你的 description 元素是带有 ait 的字符串> 元素以任意顺序混合零次或多次:

To allow your description element to be a string with a and it elements mixed in zero or more times in any order:

  • 在 XSD 中将 mixed="true" 用于 混合内容.
  • 使用 xs:choiceminOccurs="0" 来允许 ait永远不会出现.
  • 使用 xs:choicemaxOccurs="unbounded" 来允许 ait出现多次.
  • Use mixed="true" in XSD for mixed content.
  • Use xs:choice with minOccurs="0" to allow a and it to never appear.
  • Use xs:choice with maxOccurs="unbounded" to allow a and it to appear multiple times.
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="description">
    <xs:complexType mixed="true">
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="a">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:string">
                <xs:attribute name="href" type="xs:string"/>
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
        <xs:element name="it" type="xs:string" />
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

这篇关于需要 XSD 中混合内容的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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