Include Elements in XSD Complex Type Without New Element

I have this complex type:

<xsd:complexType name="Identifier">
    <xsd:sequence>
        <xsd:element name="Id" type="xsd:string"/>
        <xsd:element name="Version" type="xsd:string"/>
    </xsd:sequence>
</xsd:complexType>

Now I want to include this in another complex type, and I did it like this:

<xsd:complexType>
    <xsd:sequence>
        <xsd:element name="Id" type="Identifier"/>
              <!-- More elements here -->
    </xsd:sequence>
</xsd:complexType>

This is not what I really want. I want to include elements of type identifier directly in the second complex type without creating a new element. For example. just as it is done:

<xsd:complexType>
    <xsd:sequence>
        <xsd:element name="Id" type="xsd:string"/>
        <xsd:element name="Version" type="xsd:string"/>
              <!-- More elements here -->
    </xsd:sequence>
</xsd:complexType>

Hope this makes sense.

Thanks in advance.

+5
source share
2 answers

You can extend types, for example:

<xsd:complexType name="MySubType">
    <xsd:complexContent>
        <xsd:extension base="Identifier">
                       <xsd:sequence>
                            <!-- More elements here -->
                       </xsd:sequence>
        </xsd:extension>
    </xsd:complexContent>
</xsd:complexType>
+6
source

this complex type will always solve

<Identifier>
   <Id>string</Id>
   <Version>string</Version>
</Identifier>

if you do not need a child structure, you can define Id and Version as elements and reference them using

<xsd:element ref="Id"/>
<xsd:element ref="Version"/>

later. But then you have no guarantee that they both occur

Identifier

Mike

+1

All Articles