有没有办法在没有包装标签的情况下嵌套复杂类型?

Is there a way to nest complexTypes without a wrapper tag?

我有一个 <choice>,我需要将它的当前元素拉出到它自己的类型中(以便它可以被其他 complexTypes 引用)。有没有不需要包装标签的方法?

这是我目前拥有的:

复杂类型:

<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 中,这是我不想要的。有什么想法吗?

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

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