简体   繁体   English

cvc-elt.1:找不到元素“ countries”的声明

[英]cvc-elt.1: Cannot find the declaration of element 'countries'

cvc-elt.1: Cannot find the declaration of element 'countries' cvc-elt.1:找不到元素“ countries”的声明

I am new learner of xml schema validation and found above error with 我是xml模式验证的新手,并发现上述错误

fileSchema.xsd: 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 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 -test.namespace
-urn:Test.Namespace -urn:Test.Namespace

instead of "http://localhost:8080/ajaxprac" 而不是"http://localhost:8080/ajaxprac"
but facing same error. 但面临同样的错误。

Please find the error. 请找到错误。
Thanks in advance. 提前致谢。

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. 我认为这一定与您运行验证的方式有关:模式或源文档没有错。

I think in your example, the only thing you needed to make it run is to uncomment this line: 我认为在您的示例中,使它运行所需的唯一操作是取消注释此行:

//f.setNamespaceAware(true);

NB your mistake helped me :), and I'm happy. 注意:您的错误帮助了我:),我很高兴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM