如何在 XSD 中混合子 XML 元素和文本 [英] How to mix child XML elements with text in XSD

查看:18
本文介绍了如何在 XSD 中混合子 XML 元素和文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下 XML:

<name stamped-on-monument="unknown" remarks="name 2001/12/20">
  0011953U556K
  <aka stamped-on-monument="unknown" remarks="">
    00153U556K
  </aka>
</name>

在元素中具有内部文本"值和子元素是否可以接受?

Is it acceptable to have "inner text" value and children in an element?

如何在 XML 架构文档中定义它?

How can I define this in an XML Schema document?

推荐答案

是的,您正在描述 混合内容,可以通过 xs:complexType 上的 mixed="true" 指定:

Yes, you're describing mixed content, which can be specified via mixed="true" on xs:complexType:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="name">
    <xs:complexType mixed="true">
      <xs:sequence>
        <xs:element name="aka">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:string">
                <xs:attributeGroup ref="commonAttrs"/>
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attributeGroup ref="commonAttrs"/>
    </xs:complexType>
  </xs:element>

  <xs:attributeGroup name="commonAttrs">
    <xs:attribute name="stamped-on-monument"/>
    <xs:attribute name="remarks"/>
  </xs:attributeGroup>
</xs:schema>

这篇关于如何在 XSD 中混合子 XML 元素和文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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