我必須驗證一個可以遵循兩種給定格式的 complexType。<section>必須出現兩次。<section>可以兩次都遵循第一種格式,兩次都遵循第二種格式,或者每次都遵循 format1 和 format2 的組合。
<!--FORMAT 1-->
<section>
<!-- <section> can follow one of two formats -->
<!-- Elements will appear in sequence-->
<title>I'm a title</title>
<authors>
<author>Helen Sharp</author>
<author>Yvonne Rogers</author>
<author>Jenny Preece</author>
</authors>
<publisher year="2019">Wiley</publisher>
</section>
<!--FORMAT 2-->
<section>
<!-- Elements will appear in sequence-->
<isbn>
<isbn>1119547253</isbn>
<isbn>9781119547259</isbn>
</isbn>
<notes> I'm a note </notes>
<format>Print book</format>
<edition>5</edition>
<subjects>
<subject>Hello</subject>
</subjects>
</section>
我想也許我可以使用<xs:choice>,然后<xs:sequence>在里面,但我得到了以下錯誤:Element 'choice' Is Invalid, Misplaced, Or Occurs Too Often.
到目前為止,我的代碼如下所示:
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="section" minOccurs="2" maxOccurs="2">
<xs:complexType>
<xs:choice> <!--This choice will be for format 1-->
<xs:sequence>
<!--other validation for format1-->
</xs:sequence>
</xs:choice>
<xs:choice> <!--This choice will be for format 2-->
<xs:sequence>
<!--other validation for format2-->
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
我可以理解為什么這行不通,但這是我唯一能想到的。也許我缺少一些東西?任何幫助都會非常棒:)
uj5u.com熱心網友回復:
代替
<xs:choice>
<xs:sequence>
<!--other validation for format1-->
</xs:sequence>
</xs:choice>
<xs:choice>
<xs:sequence>
<!--other validation for format2-->
</xs:sequence>
</xs:choice>
經過
<xs:choice>
<xs:sequence>
<!--other validation for format1-->
</xs:sequence>
<xs:sequence>
<!--other validation for format2-->
</xs:sequence>
</xs:choice>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/454741.html
