【问题标题】:How to write xsd schema to allow me to miss the top level tag in xsd definition?如何编写 xsd 架构以允许我错过 xsd 定义中的顶级标记?
【发布时间】:2014-07-06 12:18:29
【问题描述】:

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

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

<tt>blah</tt>

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

【问题讨论】:

  • 您的示例实例都不是格式正确的,所以我不确定您的问题到底是什么意思。

标签: xml xsd ttml


【解决方案1】:

只是一个提示

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

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

【讨论】:

  • 哦,我明白了。我不知道您可以将两个元素作为根放在一个 xsd 中。将尝试并标记为已接受。
  • 单个 xsd 但创建了两个我想避免的类。嗯..无论如何你的回答对于我问的问题是正确的。
猜你喜欢
  • 2021-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-06
  • 1970-01-01
  • 2016-08-13
  • 2011-05-24
  • 1970-01-01
相关资源
最近更新 更多