It works for me. I think it must be something to do with the way you are running the validation: there's nothing wrong with the schema or source document.
cvc-elt.1: Cannot find the declaration of element 'countries'
Question
cvc-elt.1: Cannot find the declaration of element 'countries'
I am new learner of xml schema validation and found above error with
fileSchema.xsd:
> <xs:schema version="1.0"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://localhost:8080/ajaxprac"
> xmlns="http://localhost:8080/ajaxprac"
> elementFormDefault="qualified">
>
> <xs:element name="countries" type="xs:string"/>
> </xs:schema>
file.xml
<countries xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://localhost:8080/ajaxprac"
xsi:schemaLocation="http://localhost:8080/ajaxprac fileSchema.xsd">
This is the xml with just root element
</countries>
Factory Setting
DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
f.setValidating(true);
//f.setNamespaceAware(true);
try {
f.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
} catch (IllegalArgumentException e) {
System.out.println("Exception Occured: "+e.getMessage());
}
I have used
-test.namespace
-urn:Test.Namespace
instead of "http://localhost:8080/ajaxprac"
but facing same error.
Please find the error.
Thanks in advance.
Solution
OTHER TIPS
I think in your example, the only thing you needed to make it run is to uncomment this line:
//f.setNamespaceAware(true);
N.B. your mistake helped me :), and I'm happy.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow