Error with XSD validation: “cvc-elt.1: Cannot find the declaration of element 'xs:schema'”

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 12:33:38

问题


I am trying to use the Maven XML plugin to validate my xml against a schema but I keep having an error saying:

cvc-elt.1: Cannot find the declaration of element 'xs:schema'.

I guess it has to deal with my namespaces declaration, so here they are:

In my 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">

In my XML:

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

What is wrong with those declarations? What do I need to modify?

Thanks for your help.


回答1:


In your 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>

and in your catalog file src/main/resources/xsd/catalog.xml

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

For more information on catalog configuration see Maven Plugin Catalog



来源:https://stackoverflow.com/questions/7348353/error-with-xsd-validation-cvc-elt-1-cannot-find-the-declaration-of-element-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!