0

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

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

<tt>blah</tt>

我尝试minOccurs了标题,但由于它是根本,它不可能是minOccurs = 0次。那么,如何实现呢?

4

1 回答 1

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>

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

于 2014-07-07T06:46:41.313 回答