XSD验证出错:“cvc-elt.1:无法找到元素'xs:schema'的声明”

时间:2011-09-08 12:54:57

标签: xml xsd xerces xsd-validation

我正在尝试使用Maven XML插件来验证我的xml对模式,但我一直有错误说:

  

cvc-elt.1:找不到元素'xs:schema'的声明。

我想它必须处理我的命名空间声明,所以这里是:

在我的XSD中:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns="http://www.myurl.com/schemas" 
  targetNamespace="http://www.myurl.com/schemas" 
  elementFormDefault="qualified" version="1.0">

在我的XML中:

<myTag xmlns="http://www.myurl.com/schemas">

这些声明有什么问题?我需要修改什么?

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

在你的pom.xml中

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>xml-maven-plugin</artifactId>
    <executions>
      <execution>
        <goals>
          <goal>validate</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <catalogs>
          <catalog>src/main/resources/xsd/catalog.xml</catalog>
      </catalogs>
      <validationSets>
        <validationSet>
          <dir>src/main/resources/xsd</dir>
          <systemId>src/main/resources/xml/mytag.xml</systemId>
        </validationSet>
      </validationSets>
    </configuration>
  </plugin>

并在目录文件src / main / resources / xsd / catalog.xml

<catalog>
    <system systemId="http://www.w3.org/2001/XMLSchema" uri="http://www.w3.org/2001/XMLSchema.xsd"/>
</catalog>

有关目录配置的更多信息,请参阅Maven Plugin Catalog

相关问题