如何编写xsd模式以允许我错过xsd定义中的顶级标记?

时间:2014-07-06 12:18:30

标签: xml xsd ttml

我想创建一个对两种类型的XML文件都有效的XSD架构:

<caption> 
    <tt>blah</tt>
</caption>

<tt>blah</tt>

我尝试使用minOccurs作为标题,但由于它是根,因此不能minOccurs = 0次。那么,如何实现这一目标呢?

1 个答案:

答案 0 :(得分:0)

只是提示

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <!-- First possible root element -->
    <xs:element name="tt" type="xs:string"/>

    <!-- Second possible root element-->
    <xs:element name="caption">
        <xs:complexType>
            <xs:sequence>
                <!-- just reference to first defined element - when something change there, it won't be necessary to change it everywhere -->
                <xs:element ref="tt" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>

显然还有其他方法可以达到同样的效果。

相关问题