2010-06-15 31 views
0

我有這塊XML的驗證問題:問題的XML架構的制定基於存在的XML

<?xml version="1.0" encoding="UTF-8"?> 
<i-ching xmlns="http://www.oracolo.it/i-ching"> 
    <predizione> 
     <esagramma nome="Pace"> 
      <trigramma> 
       <yang/><yang/><yang/> 
      </trigramma> 
      <trigramma> 
       <yin/><yin/><yin/> 
      </trigramma> 
     </esagramma> 
     <significato>Questa combinazione preannuncia 
      <enfasi>boh</enfasi>, e forse anche <enfasi>mah, 
       chissa</enfasi>.</significato> 
    </predizione> 
    <predizione> 
     <esagramma nome="Ritorno"> 
      <trigramma> 
       <yang/><yin/> <yin/> 
      </trigramma> 
      <trigramma> 
       <yin/><yin/><yin/> 
      </trigramma> 
     </esagramma> 
     <significato>Si prevede con certezza <enfasi>qualcosa</enfasi>, 
      <enfasi>ma anche <enfasi>no</enfasi></enfasi>.</significato> 
    </predizione> 
</i-ching> 

該XML模式與俄羅斯娃娃技術開發:

<?xml version="1.0" encoding="UTF-8"?> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns="http://www.oracolo.it/i-ching" 
    targetNamespace="http://www.oracolo.it/i-ching" 
    > 

<xsd:element name="i-ching"> 
    <xsd:complexType> 
     <xsd:sequence> 
      <xsd:element name="predizione" minOccurs="0" maxOccurs="64"> 
       <xsd:complexType> 
        <xsd:sequence> 
         <xsd:element name="esagramma"> 
          <xsd:complexType> 
           <!-- vi sono 2 trigrammi --> 
           <xsd:sequence> 
            <xsd:element name="trigramma" minOccurs="2" maxOccurs="2"> 
             <xsd:complexType> 
              <xsd:sequence minOccurs="3" maxOccurs="3"> 
               <xsd:choice> 
                <xsd:element name="yang"/> 
                <xsd:element name="yin"/> 
               </xsd:choice> 
              </xsd:sequence> 
             </xsd:complexType> 
            </xsd:element> 
           </xsd:sequence> 
           <xsd:attribute name="nome" type="xsd:string"/> 
          </xsd:complexType> 
         </xsd:element> 
         <!-- significato: context model misto --> 
         <xsd:element name="significato"> 
          <xsd:complexType mixed="true"> 
           <xsd:sequence> 
            <xsd:element name="enfasi" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/> 
           </xsd:sequence> 
          </xsd:complexType> 
         </xsd:element> 
        </xsd:sequence> 
       </xsd:complexType> 
      </xsd:element> 
     </xsd:sequence> 
    </xsd:complexType> 
</xsd:element> 

</xsd:schema> 

對於練習,我必須開發一個XML模式來驗證以前的XML。問題是氧氣對我說:

cvc-complex-type.2.4.a: Invalid content was found starting with element 'predizione'. One of '{predizione}' is expected. Start location: 3:6 End location: 3:16 URL: http://www.w3.org/TR/xmlschema-1/#cvc-complex-type 

爲什麼?這是我的xml架構錯了嗎? 非常感謝你

+0

我寫同樣的運動與其他技術。我發佈了練習,希望能幫助別人: 薩拉米切片:http://pastebin.com/AJkk0V3A 伊甸園:http://pastebin.com/7Cw38yxB 威尼斯盲人:http://pastebin.com/ VPsSz9KA – farhad 2010-06-16 09:40:07

回答

1

它尋找predizione一個空的命名空間,但它只能發現在默認命名空間http://www.oracolo.it/i-chingpredizione,因爲你沒有elementFormDefault="qualified"xsd:schema元素設置做。 You can read more about this attribute and why it's needed here

基本上是你最簡單的解決方法是使用以下命令:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns="http://www.oracolo.it/i-ching" 
    targetNamespace="http://www.oracolo.it/i-ching" 
    elementFormDefault="qualified" 
    > 
+0

非常感謝!我在學習的時候誤解了這個觀點:現在很清楚,我糾正了我的模式。再次感謝你 – farhad 2010-06-16 08:13:27