XSD Base complexType

时间:2015-01-28 10:46:06

标签: xsd

我想配置一个具有特定子项的基类型。 可以通过配置只允许一个子元素的元素来使用此类型。

<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>

现在我想把:

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

无论在哪里,它都将被相应地替换(如果它是git / svn等......)。 我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

从我可以看到你已经存在的东西,它只是缺少的东西的XML方面。

你有一个架构 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>

由于您有两件来自VscType的东西,您可以根据VscType本身,GitVscType或SvnVscType创建文档。

Liquid XML Studio - Generate XML FROM XSD Wizard

导致

<?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>