shayy
shayy

Reputation: 1312

XSD Base complexType

I'd like to configure a base type which has concrete children. This type can be used by configuring an element of which only one child is allowed.

<xs:complexType name="VcsType">
    <xs:sequence>
        <xs:element name="enabled" type="xs:boolean" default="false" minOccurs="1"/>
    </xs:sequence>
</xs:complexType>

<xs:complexType name="GitVcsType">
    <xs:complexContent>
        <xs:extension base="VcsType">
            <xs:sequence>
                <xs:element name="url" type="xs:string" minOccurs="1"/>
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

<xs:complexType name="SvnVcsType">
    <xs:complexContent>
        <xs:extension base="VcsType">
            <xs:sequence>
                <xs:element name="version" type="xs:string" minOccurs="1"/>
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

Now i'd like to just put:

<xs:element name="vcs" type="VcsType" minOccurs="0"/>

Wherever and it will be replaced accordingly (if it's git/svn etc..). How can I do that?

Upvotes: 0

Views: 155

Answers (1)

Sprotty
Sprotty

Reputation: 5973

From what I can see your already there, its just the XML side of things thats missing.

You have a schema Liquid XML Studio Schema Diagram

<?xml version="1.0" encoding="utf-8" ?>
<!-- Created with Liquid XML 2015 Designer Edition (Trial) 13.0.1.5719 (http://www.liquid-technologies.com) -->
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="vcs" type="VcsType" />
    <xs:complexType name="VcsType">
        <xs:sequence>
            <xs:element name="enabled" type="xs:boolean" minOccurs="1" default="false" />
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="GitVcsType">
        <xs:complexContent>
            <xs:extension base="VcsType">
                <xs:sequence>
                    <xs:element name="url" type="xs:string" minOccurs="1" />
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="SvnVcsType">
        <xs:complexContent>
            <xs:extension base="VcsType">
                <xs:sequence>
                    <xs:element name="version" type="xs:string" minOccurs="1" />
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
</xs:schema>

As you have 2 things deriving from VscType you can either create a document based on VscType itself, GitVscType or SvnVscType.

Liquid XML Studio - Generate XML FROM XSD Wizard

Which results in either

<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid XML 2015 Designer Edition (Trial) 13.0.1.5719 (http://www.liquid-technologies.com) -->
<vcs>
    <enabled>true</enabled>
</vcs>
<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid XML 2015 Designer Edition (Trial) 13.0.1.5719 (http://www.liquid-technologies.com) -->
<vcs xsi:type="GitVcsType" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <enabled>true</enabled>
    <url>string</url>
</vcs>
<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid XML 2015 Designer Edition (Trial) 13.0.1.5719 (http://www.liquid-technologies.com) -->
<vcs xsi:type="SvnVcsType" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <enabled>true</enabled>
    <version>1.0.0.0</version>
</vcs>

Upvotes: 1

Related Questions