Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Verify xsd scheme

Tags:

xml

xsd

I have tried to verify my scheme but it always report the same issue.

Here is my scheme

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Coches">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="Coche" minOccurs="0" maxOccurs="unbounded">
                <xsd:attribute name="anio_fabricacion" type="xsd:string">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="Bastidor" type="xsd:string"/>
                            <xsd:element name="Marca" type="xsd:string"/>
                            <xsd:element name="Modelo" type="xsd:string"/>
                            <xsd:element name="Submodelo" type="xsd:string"/>
                            <xsd:element name="Color" type="xsd:string"/>
                            <xsd:element name="Precio" type="xsd:string"/>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:attribute>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

Here is my XML document

<Coches>
    <Coche anio_fabricacion="2015">
        <Bastidor>1234567890qwertyQ</Bastidor>
        <Marca>Renault</Marca>
        <Modelo>Megane</Modelo>
        <Submodelo>Coupé</Submodelo>
        <Color>Rojo</Color>
        <Precio>18000</Precio>
    </Coche>
</Coches>

And this is the reported error.

Line:   7
Kind:   Schema Validation Error
Details:    Element '{http://www.w3.org/2001/XMLSchema}element': The content is not valid. Expected is (annotation?, ((simpleType | complexType)?, (unique | key | keyref)*)).
like image 906
Gonzalo Benedi Avatar asked Jul 28 '26 05:07

Gonzalo Benedi


1 Answers

You have an attribute surrounding a complexType which is back to front. Below is the corrected schema:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Coches">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="Coche" minOccurs="0" maxOccurs="unbounded">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="Bastidor" type="xsd:string"/>
                        <xsd:element name="Marca" type="xsd:string"/>
                        <xsd:element name="Modelo" type="xsd:string"/>
                        <xsd:element name="Submodelo" type="xsd:string"/>
                        <xsd:element name="Color" type="xsd:string"/>
                        <xsd:element name="Precio" type="xsd:string"/>
                    </xsd:sequence>
                    <xsd:attribute name="anio_fabricacion" type="xsd:string">
                    </xsd:attribute>
                </xsd:complexType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>