2016-02-05 172 views
1

Ln 19 Col 54 - s4s-elt-must-match.1:'photo'的內容必須匹配(註釋?,(simpleType | complexType)?,(unique | key | keyref) *))。發現問題始於:屬性。XML Schema將不驗證

我無法弄清楚這一點。現在已經2天了。 :(

<catalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="catalog.xsd"> 

    <photo cid="c1748" donatedBy="John Borelli"> 
     <name metadata="tunis cooper property museum">Tunis R. Cooper property</name> 
     <description> 
     <![CDATA[ 
     This photo was taken by John Borelli's great-grandfather. It is believed to have been taken around 1830. 
     David Demarest originally purchased the site of the chair factory in 1663. This site was under the ownership 
     of the Demarest family until 1758. The property is listed in the National and New Jersey Registers of Historic Places. 
     ]]> 
     </description> 
     <date>circa 1830</date> 
     <images> 
     <img src="1748a.jpg" /> 
     <img src="1748b.jpg" /> 
     </images> 
    </photo> 

    <photo cid="c1749" donatedBy="John Borelli"> 
     <name metadata="tunis cooper property museum">Tunis R. Cooper property</name> 
     <description> 
     <![CDATA[ 
     A more recent picture of the property taken by the Borelli family. The property is listed in the 
     National and New Jersey Registers of Historic Places. 
     ]]> 
     </description> 
     <date>circa 1950</date> 
     <images> 
     <img src="1749a.jpg" /> 
     </images> 
    </photo> 

    <photo cid="c1411" donatedBy="Saint Johns Catholic Church"> 
     <name metadata="saint johns catholic church">Saint Johns Church</name> 
     <description> 
     <![CDATA[ 
     A more recent picture of the property taken by the Borelli family. The property is listed in the 
     National and New Jersey Registers of Historic Places. 
     ]]> 
     </description>  
     <date>1921</date> 
    </photo> 


    <photo cid="c2003" donatedBy="Linda Choo"> 
     <name metadata="bergenfield elementary school">Bergenfield School</name> 
     <description> 
     <![CDATA[ 
     The No. 5 Public School, a.k.a. Bergenfield School 
     ]]> 
     </description> 
     <date>circa 1920</date> 
     <images> 
     <img src="2003a.jpg" /> 
     <img src="2003b.jpg" /> 
     </images> 
    </photo> 

    <photo cid="c2078" donatedBy="Maria Giodelli"> 
     <name metadata="coopers pond water">Coopers Pond</name> 
     <description> 
     <![CDATA[ 
     A favorite spot where we used to go hang out as kids. The picture shows my brothers Robert and Michael. 
     ]]> 
     </description> 
     <date>May 4, 1941</date> 
     <images> 
     <img src="2078a.jpg" /> 
     </images> 
    </photo> 

    <photo cid="c2079" donatedBy="Linda Uffington"> 
     <name metadata="watch timekeeping pocket railway">Pocket Watch</name> 
     <description> 
     <![CDATA[ 
     A more recent picture of the property taken by the Borelli family. The property is listed in the 
     National and New Jersey Registers of Historic Places. 
     ]]> 
     </description> 
     <date>circa 1870</date> 
     <images> 
     <img src="2079a.jpg" /> 
     <img src="2079b.jpg" /> 
     </images> 
    </photo> 

    <photo cid="c3233"> 
     <name metadata="hotel">Bergenfield Hotel</name> 
     <description> 
     <![CDATA[ 
     The Knollfield Hotel was known as the Bergenfield Hotel. The property is listed in the 
     National and New Jersey Registers of Historic Places. 
     ]]> 
     </description> 
     <date>circa 1920</date> 
    </photo> 

    <photo cid="c3433"> 
     <name metadata="sweeney coal fuel">Sweeney Coal</name> 
     <description> 
     <![CDATA[ 
     Sweeney Fuel Company located near New Bridge Road and railroad tracks. 
     ]]> 
     </description> 
     <date>1920</date> 
     <images> 
     <img src="3433a.jpg" /> 
     <img src="3433b.jpg" /> 
     <img src="3433c.jpg" /> 
     </images> 
    </photo> 

</catalog> 

XSD

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name="catalog"> 
    <xs:complexType> 
     <xs:sequence> 
      <xs:element name="photo" minOccurs="1" maxOccurs="unbounded"> 
      <xs:attribute name="cid" type="cidType" /> 
      <xs:attribute name="donatedBy" type="xs:string" use="optional" />    
       <xs:complexType> 
       <xs:sequence> 
        <xs:element name="name"> 
         <xs:complexType> 
          <xs:simpleContent> 
          <xs:extension base="xs:string"> 
           <xs:attribute name="metadata" type="xs:string" /> 
          </xs:extension> 
          </xs:simpleContent> 
         </xs:complexType> 
        </xs:element> 
        <xs:element name="description" type="xs:string" /> 
        <xs:element name="date" type="xs:string" /> 
        <xs:element name="images" minOccurs="0"> 
         <xs:complexType> 
          <xs:sequence> 
          <xs:element name="img"> 
           <xs:complexType> 
            <xs:simpleContent> 
            <xs:extension base="xs:string"> 
             <xs:attribute name="src" type="srcType" /> 
            </xs:extension> 
            </xs:simpleContent> 
           </xs:complexType> 
          </xs:element> 
          </xs:sequence> 
         </xs:complexType> 
        </xs:element> 
       </xs:sequence> 
       </xs:complexType> 
      </xs:element> 
     </xs:sequence> <!-- closes catalog sequence --> 
    </xs:complexType> <!-- closes catalog complex type --> 
    </xs:element> <!-- closes catalog element --> 
    <xs:simpleType name="cidType"> 
    <xs:restriction base="xs:ID"> 
     <xs:pattern value="c\d{4}" /> 
    </xs:restriction> 
    </xs:simpleType> 
<xs:simpleType name="srcType"> 
    <xs:restriction base="xs:string"> 
    <xs:pattern value="[a-zA-Z0-9]+.jpg"/> 
    </xs:restriction> 
</xs:simpleType> 

</xs:schema> 

回答

1

在您的架構中,<xs:attribute.../>聲明去<xs:complexType>...</xs:complexType>聲明中,必須付出年底,<xs:sequence>後。

一旦錯誤被修正你在定義中有XSD中的另一個問題

<xs:element name="img"> 
    <xs:complexType> 
     <xs:simpleContent> 
      <xs:extension base="xs:string"> 
       <xs:attribute name="src" type="srcType" /> 
      </xs:extension> 
     </xs:simpleContent> 
    </xs:complexType> 
</xs:element> 

你丟失的地方maxOccurs="unbounded"(或大於1,默認值)img元素的規範(假設XML實際上與images中的多個img元素有效,因爲它是複數,我猜是這種情況) 。

+0

我不得不修改。否則所有的工作。謝謝。 – David