xml 模式将序列和所有都放在一个 complexType 节点下 [英] xml schema putting both sequence and all under one complexType node
问题描述
这里是xml文件:
<section>
<number>1</number>
<title>A Title goes here...</title>
<code>TheCode</code>
<element></element>
<element></element>
</section>
在section节点中,有编号、标题和代码节点.它们的顺序不能是固定的.那么,section节点下也有多个元素.
In section node, there are number, title and code node. Their sequence must not be fixed. Then, there are multiple element under section node as well.
我们的想法是使用以下架构:
The idea is to use the following schema:
<xs:complexType name="Type-section">
<xs:all>
<xs:element name="number" minOccurs="0"></xs:element>
<xs:element name="code" minOccurs="1"></xs:element>
<xs:element name="title" minOccurs="1"></xs:element>
</xs:all>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="element"></xs:element>
</xs:sequence>
</xs:complexType>
但它是无效的.我只是不能将序列"和全部"放在同一级别.我该如何解决?
But it is invalid. I just cant put "sequence" and "all" together in the same level. How can i fix it?
推荐答案
如果顺序不重要,那么您可以这样做的一种方法是列出所有排列并将其作为选择.然而,随着选择数量的增加 O(n!),它将很难维持.由于 XML Schema 上的这些限制,我不得不为我编写的某些内容恢复顺序.
If the order must not be important, then a way you can do it is to list all the permutations and put it in as a choice. However it is going to be quite hard to maintain as the number of choices grows O(n!). I had to revert to sequence for some of the things I write because of limitations such as these on XML Schema.
例如
<choice>
<sequence>
<element name="a" />
<element name="b" />
<element name="c" />
</sequence>
<sequence>
<element name="a" />
<element name="c" />
<element name="b" />
</sequence>
<sequence>
<element name="b" />
<element name="a" />
<element name="c" />
</sequence>
<sequence>
<element name="b" />
<element name="c" />
<element name="a" />
</sequence>
<sequence>
<element name="c" />
<element name="a" />
<element name="b" />
</sequence>
<sequence>
<element name="c" />
<element name="b" />
<element name="a" />
</sequence>
</choice>
这篇关于xml 模式将序列和所有都放在一个 complexType 节点下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!