繁体   English   中英

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

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

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

我是xml模式验证的新手,并发现上述错误

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>

出厂设置

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());
        }

我用过
-test.namespace
-urn:Test.Namespace

而不是"http://localhost:8080/ajaxprac"
但面临同样的错误。

请找到错误。
提前致谢。

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

我认为在您的示例中,使它运行所需的唯一操作是取消注释此行:

//f.setNamespaceAware(true);

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

暂无
暂无

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

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