cvc-elt.1.a: Cannot find the declaration of element
The document's root element is not declared in the schema it is validated against.
cvc-elt.1.a: Cannot find the declaration of element 'invoice'.
Why it happens
- A namespace mismatch: the schema has a
targetNamespaceand the document's root has noxmlns, or a different one. This is by far the most common cause. - The wrong schema for this document, or a schema whose root element is declared in another file it imports.
- The root element is declared only locally, inside another element, not as a global
xs:element.
How to fix it
Compare the root element's name and namespace with the global elements of the schema: they must match exactly. Add the namespace declaration the schema expects to the root element, or validate with the right schema.
Java's schema validation (javax.xml.validation.Validator, and JAXB or Spring on top of it) throws at the first error unless you set an ErrorHandler whose error() records the SAXParseException and carries on; each one has getLineNumber() and getColumnNumber(). A well-formedness error ends parsing whatever the handler does.
The same problem in xmlvalid
xmlvalid validates with libxml2, which reports it as No matching global declaration available for the validation root. It checks the whole document in your browser and lists every schema error with its line and column, not only the first.
Element 'invoice': No matching global declaration available for the validation root.
Example
Validated against order.xsd, below.
<invoice currency="EUR">
<id>A-1</id>
<qty>1</qty>
</invoice>
<order currency="EUR">
<id>A-1</id>
<qty>1</qty>
</order>
order.xsd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="order">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:string"/>
<xs:element name="qty" type="xs:int"/>
<xs:element name="status" type="Status" minOccurs="0"/>
<xs:element name="code" type="Code" minOccurs="0"/>
<xs:element name="note" type="Short" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="currency" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:simpleType name="Status">
<xs:restriction base="xs:string">
<xs:enumeration value="open"/>
<xs:enumeration value="paid"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Code">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z]{3}-[0-9]{4}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Short">
<xs:restriction base="xs:string">
<xs:maxLength value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>