有没有办法在没有包装标签的情况下嵌套 complexTypes? [英] Is there a way to nest complexTypes without a wrapper tag?

查看:30
本文介绍了有没有办法在没有包装标签的情况下嵌套 complexTypes?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ,我需要将其从当前元素中提取到它自己的类型中(以便其他 complexTypes 可以引用它).有没有办法在不需要包装标签的情况下做到这一点?

I have a <choice> that I need to pull out of its current element into its own type (so that it can be referenced by other complexTypes). Is there a way to do that without needing a wrapper tag?

这是我目前所拥有的:

复杂类型:

<xs:complexType name="MyType">
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element ref="type1"/>
            <xs:element ref="type2"/>
        </xs:choice>
</xs:complexType>  

并引用它

<xs:complexType name="AdaptabilitySettingMetadataBase" abstract="true">
    <xs:sequence>
        <!-- other elements -->
        <xs:element name="MyTypeInClass" type="MyType"
                    minOccurs="0"  maxOccurs="unbounded"/>
    </xs:sequence>
</xs:complexType>

这有效,但只允许我将 type1type2 放在标签 MyTypeInClass 中,这是我不想要的.有什么想法吗?

This works, but only allows me to put the type1 and type2s within the tag MyTypeInClass, which I don't want. Any ideas?

推荐答案

使用 xs:group 而不是 xs:complexType 来实现您的目标:

Use xs:group rather than xs:complexType to achieve your goal:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns="http://www.esocial.gov.br/schema/evt/evtCS/v02_02_00"
           targetNamespace="http://www.esocial.gov.br/schema/evt/evtCS/v02_02_00"
           elementFormDefault="qualified" attributeFormDefault="unqualified">

  <xs:element name="elem1"/>
  <xs:element name="elem2"/>

  <xs:group name="MyType">
    <xs:choice>
      <xs:element ref="elem1"/>
      <xs:element ref="elem2"/>
    </xs:choice>
  </xs:group>

  <xs:complexType name="AdaptabilitySettingMetadataBase" abstract="true">
    <xs:sequence>
      <!-- other elements -->
      <xs:group ref="MyType" minOccurs="0"  maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>     
</xs:schema>  

这篇关于有没有办法在没有包装标签的情况下嵌套 complexTypes?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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