我正在尝试使用 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">
这些声明有什么问题吗?我需要修改什么?
感谢您的帮助。
在你的 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 插件目录 http://mojo.codehaus.org/xml-maven-plugin/examples/catalog.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)