简体   繁体   English

XSD,使用无序元素创建模式,其中还包含列表

[英]XSD, create schema with unordered elements that also contains list

I have that kind of XML:我有那种XML:

<HEAD>
    <BUYER>1111</BUYER>
    <RECIPIENT>2222</RECIPIENT>
    <ADDRESS>33333</ADDRESS>
    <POSITION>
        <NUMBER>1</NUMBER>
        <NAME>Name 1</NAME>
    </POSITION>
    <POSITION>
        <NUMBER>2</NUMBER>
        <NAME>Name 2</NAME>
    </POSITION>
    <POSITION>
        <NUMBER>3</NUMBER>
        <NAME>Name 3</NAME>
    </POSITION>
</HEAD>

BUYER , RECIPIENT , ADDRESS tags can be placed in any order, but before position tags . BUYER , RECIPIENT , ADDRESS标签可以按任何顺序放置,但在 position 标签之前 Tags inside POSITION can be in any order. POSITION中的标签可以按任意顺序排列。

I was trying to use all tag to describe like this:我试图使用all标签来描述这样的:

<xs:element name="HEAD">
    <xs:complexType>
        <xs:all>
            <xs:element name="BUYER">
            <xs:element name="RECIPIENT">
            <xs:element name="ADDRESS">
            <xs:element name="POSITION" maxOccurs="unbounded" minOccurs="1">
                <xs:complexType>
                     <xs:all>
                         <xs:element name="NUMBER">
                         <xs:element name="NAME">
                     </xs:all>
                <xs:complexType>
            </xs:element>
       </xs:all>
    </xs:complexType>
 </xs:element>

Howerver, I found out that unbounded could not be used in all .但是,我发现unbounded all无法使用。

Is it possible to somehow make schema, that has unordered tags with array?是否有可能以某种方式制作具有数组无序标签的模式?

In XSD 1.0 the only way to achieve this is to enumerate all permitted orderings of BUYER, RECIPIENT, and ADDRESS.在 XSD 1.0 中,实现此目的的唯一方法是枚举所有允许的 BUYER、RECIPIENT 和 ADDRESS 顺序。

In XSD 1.1 you could use xs:all to allow the elements to appear in any order, and then use an assertion to constrain it: test="every $P in POSITION satisfies empty($P/following-sibling::*[not(self::POSITION)]) .在 XSD 1.1 中,您可以使用 xs:all 来允许元素以任何顺序出现,然后使用断言对其进行约束: test="every $P in POSITION satisfies empty($P/following-sibling::*[not(self::POSITION)])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM