users@jaxb.java.net

Re: Inherited classes

From: Felipe Gaúcho <fgaucho_at_gmail.com>
Date: Mon, 21 Jul 2008 09:58:47 +0200

Hi Vity,

you can declare inheritance in xsd as well, using the element: "xsd:extension"

try this:

<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://jaxb.dev.java.net/vity/metadata"
        xmlns:metadata="http://jaxb.dev.java.net/vity/metadata"
        elementFormDefault="qualified">

        <xsd:complexType name="FooBar" abstract="true">
                <xsd:sequence>
                        <xsd:element name="x" type="xsd:int" />
                        <xsd:element name="y" type="xsd:int" />
                </xsd:sequence>
        </xsd:complexType>

        <xsd:element name="Foo">
                <xsd:complexType>
                        <xsd:complexContent>
                                <xsd:extension base="metadata:FooBar">
                                        <xsd:sequence>
                                                <xsd:element name="q" type="xsd:string" />
                                        </xsd:sequence>
                                </xsd:extension>
                        </xsd:complexContent>
                </xsd:complexType>
        </xsd:element>

        <xsd:element name="Bar">
                <xsd:complexType>
                        <xsd:complexContent>
                                <xsd:extension base="metadata:FooBar">
                                        <xsd:sequence>
                                                <xsd:element name="q" type="xsd:string" />
                                        </xsd:sequence>
                                </xsd:extension>
                        </xsd:complexContent>
                </xsd:complexType>
        </xsd:element>