tags:

views:

1703

answers:

7

I have and xsd like this

< xsd:complexType name="A">  
        < xsd:complexContent>  
            < xsd:sequence>  
                < xsd:element name="options">  
                    < xsd:complexType>  
                        < xsd:sequence>  
                            < xsd:element name="Day">  
                            ...  
                            < /xsd:element>  
                        < /xsd:sequence>  
                    < /xsd:complexType>  
                < /xsd:element>  
            < /xsd:sequence>  
        < /xsd:complexContent>  
< /xsd:complexType>  

< xsd:complexType name="B">  
    < xsd:complexContent>
        < xsd:extension base="A">
        ...What would go here...
        < /xsd:extension>
    < /xsd:complexContent>
< /xsd:complexType>

So basically I want class A to have a sequence of options Day, Week for example then I want B to inherit form A and have all of A's options and an additional 2 or 3 options like hours, seconds.

A: 

Simply add an with the required elements:

<xsd:complexType name="B">  
    <xsd:complexContent>
        <xsd:extension base="A">
           <xsd:sequence>
              <xsd:element name="Hours">
              ...
              </xsd:element>
           </xsd:sequence>
        </xsd:extension>
    </xsd:complexContent>
</xsd:complexType>
csgero
A: 

That adds Hours to B and not to B.options where I need it to be.

arinte
A: 

Can you give an example of what you would you like your output to look like?

Millhouse
A: 

You'll need to create a type for options, which contains hours etc, and then add options instead of hours in csgero's answer.

tunaranch
+5  A: 

Here's the schema I came up with:

<?xml version="1.0" encoding="utf-8"?>
<schema id="inheritance"
    targetNamespace="http://test.com"
    elementFormDefault="qualified"
    xmlns="http://www.w3.org/2001/XMLSchema"
    xmlns:test="http://test.com"
>
    <element name="Time">
     <complexType>
      <sequence>
       <element name="First" type="test:A" />
       <element name="Second" type="test:B" />
      </sequence>
     </complexType>
    </element>

    <complexType name="shortOptions">
     <sequence>
      <element name="Day" />
     </sequence>
    </complexType>

    <complexType name="longOptions">
     <complexContent>
      <extension base="test:shortOptions">
       <sequence>
        <element name="Week" />
       </sequence>
      </extension>
     </complexContent>
    </complexType>

    <complexType name="A">
     <sequence>
      <element name="options" type="test:shortOptions" />
     </sequence>
    </complexType>

    <complexType name="B">
     <sequence>
      <element name="options" type="test:longOptions" />
     </sequence>
    </complexType>

</schema>

Which seems to fit this xml:

<?xml version="1.0" encoding="utf-8" ?>
<Time xmlns="http://test.com"&gt;
    <First>
     <options>
      <Day>Today</Day>
     </options>
    </First>
    <Second>
     <options>
      <Day>Tomorrow</Day>
      <Week>This Week</Week>
     </options>
    </Second>
</Time>
Richard Nienaber
+1  A: 

You will need to define options as a complex type of it's own, then use extension on that to create a new options complex type and use substitution instead of extension.

nedruod
A: 

damagednoob gave me exactly what I was looking for. Thanks

arinte
you should accept my answer then :)
Richard Nienaber