如何以任意顺序具有多个元素?

时间:2020-02-15 21:13:22

标签: xml xsd

我有这个XML

<contacts> 
        <entry id="10">                                             
            <commonName>Susan Sonntag</commonName>
            <tel>+844332232323</tel> 
            <email>susan23@evermail.com</email> 
            <email>susa112@private.uk</email>
        </entry>
        <entry id="20">
            <commonName>John Balber</commonName>                   
            <email>balber@hatebook.com</email>
            <tel>017297123232</tel>
            <email>home@balber.org</email>
        </entry>
        <entry id="25">
            <commonName>Mary Palmer</commonName>
            <tel>017297123232</tel>
        </entry>
</contacts>

我希望<tel><email>以任何顺序出现,并且也是可选的(零或无界)。 我是用xs:choice maxOccurs="unbounded"做的,但是我不确定它是否有效。 尽管不确定这是否正确,这是有效的。

 <xs:choice maxOccurs="unbounded">                                   
   <xs:element name="tel" type="telType"/>
   <xs:element name="email" type="emailType"/>
 </xs:choice>     

AFAIK xs:choice意味着我只能使用其中一个,但是maxOccurs="unbounded允许我以任何顺序使用所有它们。

可以吗?如果没有,还有其他方法吗?

我不确定xs:choice到底做什么。这是否意味着顺序无关紧要,或者我可以使用一个元素?

xs:choice minOccurs="0" maxOccurs="unbounded"到底是什么?那是否意味着我可以使用0到无限个元素?

那呢?

<xs:sequence minOccurs="0" maxOccurs="unbounded">
    <xs:choice>
    ...
    </xs:choice>
</xs:sequence>

0 个答案:

没有答案