1

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.

4

2 回答 2

2

这个对我有用。我认为这一定与您运行验证的方式有关:模式或源文档没有任何问题。

于 2013-06-15T18:10:45.390 回答
0

我认为在你的例子中,你唯一需要让它运行的是取消注释这一行:

//f.setNamespaceAware(true);

注意你的错误帮助了我:),我很高兴。

于 2015-04-28T08:01:42.310 回答