cvc-elt.1.a: Cannot find the declaration of element 'familia'

Viewed 250

I'm trying to validate a really simple xml using xsd, but for some reason I get this error.

cvc-elt.1.a: Cannot find the declaration of element 'familia'

Also, exists a problem in the element "nome":

src-resolve: Cannot resolve the name 'nome' to a(n) 'element declaration' component.

I'll really appreciate if someone can explain me why.

XML File

<?xml version="1.0" encoding="UTF-8"?>

<familia xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://www.painatal.pt/familia"
         xsi:schemaLocation="http://www.painatal.pt/familia familia.xsd">
            
    <detalhesFamilia>
        <nome>Familia</nome>
        <pais>Portugal</pais>
        <cidade>Porto</cidade>
        <dataNascimento>2000-02-01</dataNascimento>
        <numeroMembros>5</numeroMembros>
    </detalhesFamilia>

    <prefDias>
        <numeroDias>5</numeroDias>
    </prefDias>
</familia>

XSD File

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="familia"
           elementFormDefault="qualified">

<xs:element name="nome" type="xs:string"/>
<xs:element name="pais" type="xs:string"/>
<xs:element name="cidade" type="xs:string"/>
<xs:element name="dataNascimento" type="xs:date"/>
<xs:element name="numeroMembros" type="xs:integer"/>
<xs:element name="numeroDias" type="xs:integer"/>

<xs:element name="familia">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="nome"/>
            <xs:element ref="pais"/>
            <xs:element ref="cidade"/>
            <xs:element ref="dataNascimento"/>
            <xs:element ref="numeroMembros" minOccurs="1" maxOccurs="7"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

<xs:element name="prefDias">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="numeroDias" minOccurs="1" maxOccurs="5"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

</xs:schema>
1 Answers

The target namespace defined in the schema ("familia") doesn't match the actual namespace used in the instance ("http://www.painatal.pt/familia").

Furthermore, within the schema, <xs:element ref="nome"/> is a reference to a no-namespace element with local name nome; you want <xs:element ref="p:nome"/> where the namespace prefix p is bound to the (corrected) target namespace of the schema.

Related