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"
但也面临着同样的错误。
请找出错误所在。
提前谢谢。
发布于 2013-06-16 02:10:45
这对我很管用。我认为这一定与您运行验证的方式有关:模式或源文档没有任何错误。
发布于 2015-04-28 16:01:42
我认为在您的示例中,要使其运行,唯一需要做的就是取消对该行的注释:
//f.setNamespaceAware(true);
注:你的错误帮助了我:),我很高兴。
https://stackoverflow.com/questions/17125266
复制相似问题