Search code examples
xmlxsdxsd-validationxml-validation

Cvc-elt.1.a: Cannot Find The Declaration Of Element


When validating the XML I get the error:

Cvc-elt.1.a: Can not Find The Declaration Of Element 'ValidaLinea'

This is the XML:

 <?xml version="1.0" encoding="UTF-8"?>
<ValidaLinea>
    <cveBanco>40058</cveBanco>
    <importe>0</importe>
    <fechaHoraEnvio>2002-05-30T09:00:00</fechaHoraEnvio>
    <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">  
    </Signature>
</ValidaLinea>

And this is the XSD:

 <?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"  
            >
<xs:complexType name="ValidaLinea">
    <xs:sequence>
        <xs:element name="cveBanco">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:pattern value="[0-9]{5}" />
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
        <xs:element name="importe">
            <xs:simpleType>
                <xs:restriction base="xs:long">
                    <xs:totalDigits value="14" />
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
        <xs:element name="fechaHoraEnvio">
            <xs:simpleType>
                <xs:restriction base="xs:dateTime">
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
        <xs:element name="Signature" />
    </xs:sequence>
</xs:complexType> 
</xs:schema>

I get an error when I try to validate the XML with the XSD, the error is that it does not recognize the ValidaLinea element.


Solution

  • You've only declared a type for ValidaLinea.

    To declare an element for ValidaLinea, add to xs:schema:

    <xs:element name="ValidaLinea" type="ValidaLinea"/>
    

    Note that you might want to clean-up naming and use ValidaLineaType for the type.