2009-07-23 47 views
2

<xs:group>是否有任何理由不能在<xs:all>內出現,但只有在<xs:sequence>之內?如何解決「xs:group不能放入xs:all」的限制?

我們來看一個例子。假設有一個標籤列表(<a><d><e><f> - 請參閱下面的示例),它們不以任何特定順序出現,但總是包裝到另一個對象中(<foo><bar>); <foo> = {<a>,<b>,<c>,<d>}; <bar> = {<e><b><c><f>}:

<foo> 
    <a>a1</a> 
    <b>b1</b> 
    <c>c1</c> 
    <d>d1</d> 
</foo> 

<foo> 
    <d>d2</d> 
    <b>b2</b> 
    <c>c2</c> 
    <a>a2</a> 
</foo> 

<bar> 
    <e>e3</e> 
    <b>b3</b> 
    <c>c3</c> 
    <f>f3</f> 
</bar> 

欲限定的complexType的<foo>並在XSD <bar>當提取標籤<b><c>xs:group並使用<xs:group ref="...">。但是,由於上述限制,這是不可能的。

對於給定問題,您會提出什麼建議作爲解決方法?有可能,我正在做一些愚蠢的事情,但爲什麼這是不正確的?

+1

現在你知道我爲什麼討厭w3c了。 – Will 2009-07-23 14:22:51

+1

w3c中沒有提供這樣一個簡單的要求?壞!! – Archana 2012-01-11 06:19:57

回答

0

確定性內容規則是限制的原因。如果您想要充分理解,請閱讀van der Vlist的書或the standard

1

我不能說爲什麼這個限制存在,但我可以看到一個全功能<group>(嵌套<choice><all>)內的另一個<all>可能會有點混亂,開發商(當然,我的可能組合無論如何),尤其是對用戶。

作爲一種變通方法,我會建議你可能已經想出什麼樣的:那就是,聲明另一個<complexType><b><c>和使用裏面你<foo><bar>

<xs:complexType name="bcType"> 
    <xs:all> 
     <xs:element name="b" type="xs:string" /> 
     <xs:element name="c" type="xs:string" /> 
    </xs:all> 
    </xs:complexType> 

    <xs:complexType name="foo"> 
    <xs:all> 
     <xs:element name="d" type="xs:string" /> 
     <xs:element name="a" type="xs:string" /> 
     <xs:element name="bc" type="bcType" /> 
    </xs:all> 
    </xs:complexType> 

    <xs:complexType name="bar"> 
    <xs:all> 
     <xs:element name="f" type="xs:string" /> 
     <xs:element name="e" type="xs:string" /> 
     <xs:element name="bc" type="bcType" /> 
    </xs:all> 
    </xs:complexType> 
相關問題