![](/img/trans.png)
[英]XML Schema construct for “Any number of these elements - in any order”
[英]xml schema construct for elements to occur any number of times in any order
我想編寫一個XML模式,該模式可以接受某些元素,這些元素可以按任意順序出現多次。 像下面的例子。 它應該滿足所有類似的組合。 租賃幫助我,在此先感謝。
<root>
<node1> one </node1>
<node1> two </node1>
<node2> three </node2>
<node1> four </node1>
<node2> five </node2>
<node2> six </node2>
</root>
<root>
<node1> one </node1>
<node2> two </node2>
<node1> three </node1>
<node2> four </node2>
<node2> five </node2>
<node1> six </node1>
<node1> seven </node1>
</root>
這樣的事情應該起作用:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="root" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="node1" nillable="true">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="node2" nillable="true">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
基本上, <xs:choice>
使您可以選擇任何一個包含的節點,例如<node1>
或<node2>
任何一個。 有關各種選項的更多說明,請參見W3Schools的文章 。
由於<xs:choice>
具有minOccurs="0"
和maxOccurs="unbounded"
屬性,因此您可以多次重復“選擇任何包含的節點”方案。
最后,您可以選擇任意數量的節點,並且每次都可以選擇node1或node2(或者,如果您向<xs:choice>
添加更多選項,則可以選擇更多個節點)
marc_s的答案就在頭上。
在編寫模式時,我發現此資源非常有用: http : //www.w3schools.com/Schema/schema_elements_ref.asp
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.