【问题标题】:Error with XSD validation: "cvc-elt.1: Cannot find the declaration of element 'xs:schema'"XSD 验证错误:“cvc-elt.1: 找不到元素 'xs:schema' 的声明”
【发布时间】:2011-09-08 12:54:56
【问题描述】:

我正在尝试使用 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">

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

感谢您的帮助。

【问题讨论】:

  • 如果可能,请发布您的整个架构。谢谢
  • 您是否在验证架构而不是实例文档?
  • @42 - 哈哈,我认为你是对的
  • 好吧,你们是对的 :-p 尽管如此,我的架构中的 xs:include 仍然存在问题 :'( ...
  • Vakimshaar 你解决了这个问题吗?

标签: xml xsd xerces xsd-validation


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多