Currently, the file which validating: Currently, the file which validating: Currently, the file which validating:

is there any way I can have two complex types in one element schema ? I'm using 1.0 V

45 views Asked by At

This is my schema file:

<xs:element name="elementname">
  <xs:complexType/>
</xs:element>

Currently, the file which validating:

<ElementDef name="elementname" visible="false">
  <elementname/>
</ElementDef>

But now I want this schema to accept this also the previous schema (i.e. I want some kind of choice that it accepts meta tag also if it has any)

<ElementDef name="elementname" visible="false">
  <Section>
    <Sequence>
      <SectionType name="meta">
    </Sequence>
  </Section>    
  <elementname/>
</ElementDef>

This is what I have tried, but doesn't work:

<xs:complexType>
  <xs:choice minOccurs="0" maxOccurs="unbounded">
    <xs:element name="Section" minOccurs="0">
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="Sequence" minOccurs="0">
          <xs:complexType>
            <xs:attribute name="name" type="xs:string" use="required"/>
            <xs:attribute name="friendly" type="xs:string" use="optional"/>
            <xs:attribute name="style" type="xs:string" use="optional"/>
            <xs:attribute name="numbering" use="optional">
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:element>
  </xs:choice>
</xs:complexType>

Please let me know if you have any suggestions.

1

There are 1 answers

0
Michael Kay On

Your post is confusing in very many ways. For example, you say in the text that you are using 1.0, but you have tagged it 1.1.

An xs:choice normally offers more than one alternative - for some reason you've got two xs:choice elements, and each of them only offers one alternative.

I think you just want a sequence in which Section is optional:

<xs:complexType>
  <xs:sequence>
     <xs:element name="Section" minOccurs="0">
       ...
     </xs:element>
     <xs:element name="elementName">
       ...
     </xs:element>
  </xs:sequence>
</xs:complexType>