2012-05-29 14 views
0

我正在第一次編寫XML模式,並且發現了一些有用的工具來幫助我編寫它。XML模式:全部,序列和組

現在我處於一種奇怪的狀況。我寫的模式適用於某些工具,而不適用於其他工具。 該模式是「全部」,「序列」和「組」的組合。這是我的XML模式:

<?xml version="1.0" encoding="utf-8"?> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <xsd:group name="test"> 

     <xsd:all> 
       <xsd:element name="e2" minOccurs="0" maxOccurs="1"/> 
       <xsd:element name="e3" minOccurs="0" maxOccurs="1"/> 
       <xsd:element name="e4" minOccurs="0" maxOccurs="1"/> 
     </xsd:all> 
    </xsd:group> 

    <xsd:element name="e0"> 
     <xsd:complexType> 
      <xsd:sequence> 
       <xsd:element name="e1" maxOccurs="unbounded"/> 
       <xsd:group ref="test"/> 
      </xsd:sequence> 
     </xsd:complexType> 
    </xsd:element> 
</xsd:schema> 

這個模式是正確的嗎? 它適合於this validatorthis one too,但Notepad ++的XML Tools插件顯示「無法解析模式文件」。

P.S:我寫了這個模式,因爲我想要一個元素「e0」,這樣可以混合使用e1,e2,e3和e4。 e2,e3和e4應該出現0或1次,並且e1可能出現無限次。 例如該XML文件要經過:

<e0> 
    <e1/> 
    <e1/> 
    <e1/> 
    <e1/> 
    <e1/> 
    <e2/> 
</e0> 

<e0> 
    <e2/> 
    <e3/> 
    <e4/> 
</e0> 

<e0> 
    <e1/> 
    <e2/> 
    <e3/> 
    <e4/> 
</e0> 

你知道的其他方式做到這一點?

感謝

回答

5

你擁有的架構似乎根據1.0版本,其中規定plainly here (Primer)

XML Schema stipulates that an all group must appear as the sole child at the top of a content model.

或者,嘗試讀取XML架構第3.8.6無效結構here。爲了您的清單我想補充.NET的XSD處理器,而你的情況會抱怨爲:

The group ref to 'all' is not the root particle, or it is being used as an extension.

隨着XSD 1.0沒有解決辦法,給你你想要很好地與的一個簡明的語法是什麼除非你爲e1元素構建一個包裝器(下面是e1s)。

<?xml version="1.0" encoding="utf-8"?> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <xsd:group name="test"> 
     <xsd:all> 
      <xsd:element name="e1s" minOccurs="0"> 
       <xsd:complexType> 
        <xsd:sequence> 
         <xsd:element name="e1" maxOccurs="unbounded"/> 
        </xsd:sequence> 
       </xsd:complexType> 
      </xsd:element> 
      <xsd:element name="e2" minOccurs="0"/> 
      <xsd:element name="e3" minOccurs="0"/> 
      <xsd:element name="e4" minOccurs="0"/> 
     </xsd:all> 
    </xsd:group> 
    <xsd:element name="e0"> 
     <xsd:complexType> 
      <xsd:group ref="test"/> 
     </xsd:complexType> 
    </xsd:element> 
</xsd:schema> 

當涉及到E1的元素,它們必須被包裹在個E1

<e0> 
    <e1s> 
     <e1/> 
     <e1/> 
     <e1/> 
     <e1/> 
     <e1/> 
    </e1s> 
    <e2/> 
</e0> 

<e0> 
    <e1s> 
     <e1/> 
    </e1s> 
    <e2/> 
    <e3/> 
    <e4/> 
</e0>  

然後,它都會驗證...

+0

這是很常見找到他們接受的過於寬泛的工具。 Xerces和Saxon都非常合適:如果這兩個人都接受它,那麼這可能是有效的。不幸的是,這並不意味着它可以在任何地方工作,因爲一些工具在他們接受的內容方面過分限制... –

+0

好的,謝謝你的回答!我會嘗試以其他方式做到這一點。 – TheArsenik

+0

奇怪的是,沒有解決方案(至少簡單)對於這樣簡單的任務 – Disappointed