Domanda

I am new to XML and XSD and I have been trying to validate this xsd code to an xml file but without any success. I am getting an error below and I cannot see what is wrong. Any help will be appreciated.

s4s-elt-invalid-content.1: The content of '#AnonType_endangered_species' is invalid. Element 'element' is invalid, misplaced, or occurs too often.

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

<xsd:element name="endangered_species">
  <xsd:complexType>

<xsd:element name="animal" type="xsd:string" minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
    <xsd:sequence>
<xsd:element name="name" minOccurs="2" maxOccurs="2" type="xs:string">
    <xsd:complexType>
        <xsd:all>
        </xsd:all>
             <xsd:attribute ref="language"> 
            <xsd:simpleType>
               <xsd:restriction base="xsd:string">
                  <xsd:enumeration value="English"/>
                  <xsd:enumeration value="Latin"/>
               </xsd:restriction>
            </xsd:simpleType>
             </xsd:attribute>
    </xsd:complexType>
</xsd:element>

    </xsd:sequence>
</xsd:complexType>
</xsd:element>  

</xsd:complexType>
</xsd:element>

</xsd:schema>
È stato utile?

Soluzione

Your xsd:element tag is misplaced. You can't have xsd:element as a child of xsd:contentType.

You probably want to place it inside a group, such as a sequence:

<xsd:complexType>
    <xsd:sequence>
         <xsd:element ...>
    ...
...

You also have other problems in that XSD. You have to choose if you are going to have nested complexType elements or if you are going to declare a simple type. You can fix it removing the type="xsd:string" attributes from the nested xs:element elements.

Finally you either refer to an attribute (which is not present in your XSD) or name it. Since you have a nested type, you probably don't want to reference it. So change <xsd:attribute ref="language"> to <xsd:attribute name="language">.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top