2017-09-18 2 views
1

Ich erhalte die Fehlermeldung Fehler - Zeile 16, 38: org.xml.sax.SAXParseException; Zeilennummer: 16; Spaltennummer: 38; cvc-complex-type.2.4.d: Ungültiger Inhalt wurde gefunden, beginnend mit dem Element 'catalog_item'. Zu diesem Zeitpunkt wird kein untergeordnetes Element erwartet. Zeile 16. Ich soll ein xsd schreiben, um eine gegebene XML-Datei zu validieren.Ungültiger Inhalt wurde gefunden, beginnend mit element.'catalog_item '

Dies ist die XML-Datei, die mir gegeben wurde.

<?xml version="1.0" encoding="UTF-8"?> 
 
<catalog> 
 
    <product description="Cardigan Sweater" product_image="cardigan.jpg"> 
 
     <catalog_item gender="Men's"> 
 
     <item_number>QWZ5671</item_number> 
 
     <price>39.95</price> 
 
     <size description="Medium"> 
 
      <color_swatch image="red_cardigan.jpg">Red</color_swatch> 
 
      <color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch> 
 
     </size> 
 
     <size description="Large"> 
 
      <color_swatch image="red_cardigan.jpg">Red</color_swatch> 
 
      <color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch> 
 
     </size> 
 
     </catalog_item> 
 
     <catalog_item gender="Women's"> 
 
     <item_number>RRX9856</item_number> 
 
     <price>42.50</price> 
 
     <size description="Small"> 
 
      <color_swatch image="red_cardigan.jpg">Red</color_swatch> 
 
      <color_swatch image="navy_cardigan.jpg">Navy</color_swatch> 
 
      <color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch> 
 
     </size> 
 
     <size description="Medium"> 
 
      <color_swatch image="red_cardigan.jpg">Red</color_swatch> 
 
      <color_swatch image="navy_cardigan.jpg">Navy</color_swatch> 
 
      <color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch> 
 
      <color_swatch image="black_cardigan.jpg">Black</color_swatch> 
 
     </size> 
 
     <size description="Large"> 
 
      <color_swatch image="navy_cardigan.jpg">Navy</color_swatch> 
 
      <color_swatch image="black_cardigan.jpg">Black</color_swatch> 
 
     </size> 
 
     <size description="Extra Large"> 
 
      <color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch> 
 
      <color_swatch image="black_cardigan.jpg">Black</color_swatch> 
 
     </size> 
 
     </catalog_item> 
 
    </product> 
 
</catalog>

Und dies ist für die oben genannte XML-Datei meine XSD-Datei.

<?xml version="1.0"?> 
 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
 
    <xs:element name="catalog"> 
 
    <xs:complexType> 
 
    <xs:sequence> 
 
    <xs:element name="product"> 
 
     <xs:complexType> 
 
     <xs:sequence> 
 
     <xs:element name="catalog_item"> 
 
     <xs:complexType> 
 
      <xs:sequence> 
 
      <xs:element name="item_number"> 
 
      <xs:simpleType> 
 
      <xs:restriction base="xs:string"> 
 
       <xs:pattern value="[A-Z][A-Z][A-Z][0-9][0-9][0-9][0-9]"/> 
 
      </xs:restriction> 
 
      </xs:simpleType> 
 
      </xs:element> 
 
      <xs:element name="price" type="xs:decimal"/> 
 
      <xs:element name="size" maxOccurs="unbounded"> 
 
     <xs:complexType> 
 
      <xs:sequence> 
 
       <xs:element name="color_swatch" maxOccurs="unbounded"> 
 
       <xs:complexType mixed="true"> 
 
        <xs:attribute name="image" type="xs:string"/> 
 
       </xs:complexType> 
 
       </xs:element> 
 
      </xs:sequence> 
 
      <xs:attribute name="description" type="xs:string"/> 
 
     </xs:complexType> 
 
    </xs:element> 
 
\t \t </xs:sequence> 
 
\t \t <xs:attribute name="gender" type="xs:string"/> 
 
\t \t </xs:complexType> 
 
     </xs:element> 
 
\t </xs:sequence> 
 
\t <xs:attribute name="description" type="xs:string"/> 
 
    <xs:attribute name="product_image" type="xs:string"/> 
 
    </xs:complexType> 
 
    </xs:element> 
 
    </xs:sequence> 
 
    </xs:complexType> 
 
</xs:element> 
 
</xs:schema>

Antwort

1

The maxOccurs occurrence constraint defaults to 1, so können Sie Ihre XSD nur für eine catalog_item, noch Ihre XML hat zwei.

Um mehr catalog_item Elemente, fügen maxOccurs="unbounded" ...

ändern

<xs:element name="catalog_item"> 

zu

<xs:element name="catalog_item" maxOccurs="unbounded"> 
zu erlauben
Verwandte Themen