[英]XSD - Elements in any order and count (XML validated by XERCES using XSD)
我有XML架構的問題。 我需要在三個類型的一個元素元素內部,但沒有任何其他限制,后面恰好出現一個元素output
:
<command path="app.exe" workingDir="/usr/local/bin">
<param name="--name" assign="=">anyName</param>
<switch name="--verbose"/>
<param name="--config">/etc/app/conf.txt</param>
<param name="--overriding">~/app/conf.txt</param>
<switch name="-d"/>
<param name="--report" assign="=">~/app/report.txt</param>
<param name="--template">~/app/templates/default.tt</param>
<string>../t/${testName}/log.txt</string>
<output>
<out path="stdout.txt"/>
<err path="stderr.txt"/>
</output>
</command>
我可以只使用sequence
, all
或choice
,但沒有一個滿足我的要求。 順序 - 按照確切的順序進行任意次數。 全部 - 任何順序為零或一次。 選擇 - 只有其中一個。 我在這個網站上找到了一個解決方案 ,但它不適用於Xerces。 我試試這個:
<xs:complexType name="commandType">
<xs:sequence>
<xs:group ref="gupa"/>
<xs:element name="output" type="outputType" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="path" use="required" type="value"/>
<xs:attribute name="workingDir" use="required" type="value"/>
</xs:complexType>
<xs:group name="gupa">
<xs:choice>
<xs:element name="env" type="pair" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="param" type="paramType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="switch" type="switchType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="string" type="value" minOccurs="0" maxOccurs="unbounded"/>
</xs:choice>
</xs:group>
但我收到錯誤: 從元素'switch'開始發現無效內容。 預計會有一個'{param,output}' 。 有一個技巧。
如果將
maxOccurs="unbounded"
從模式中的元素移動到元素choice
,則任何元素都可以以任意次數出現。
但是,當我這樣做時,我得到錯誤: 屬性'maxOccurs'不能出現在元素'choice'中
我穿過互聯網巡航,但我仍然沒有找到我正在尋找的東西。
您可以將三種元素類型放在一個選項中,然后將選擇按順序放在另一個序列中。
<xs:group name="mygr">
<xs:choice>
<xs:element name="string"></xs:element>
<xs:element name="param"></xs:element>
<xs:element name="switch"></xs:element>
<xs:element name="env"></xs:element>
</xs:choice>
</xs:group>
<xs:element name="root">
<xs:complexType>
<xs:sequence >
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:group ref="mygr"/>
</xs:sequence>
<xs:element name="output"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
這是你已經擁有的,但輸出水平更高。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.