我正在使用org.jvnet插件并尝试将xsd文件转换为Java Jaxb注释对象,以便在编组和解组中使用。但是,尝试编译简单的Xsd文件时会出错。
我认为我正在制作一个简单的语法错误,第二眼就会非常感激。如果有更多细节我应该提供,请告诉我。所有相关文件和消息都包含在下面。
错误讯息:
[ERROR] Error while parsing schema(s).Location [ file:/C:/.../project/asdfasdf/src/main/resources/RandomObjectSchema.
xsd{6,46}].
org.xml.sax.SAXParseException; systemId:
file:/C:/.../project/asdfasdf/src/main/resources/RandomObjectSchema.xsd;
lineNumber: 6; columnNumber: 46; src-resolve.4.2: Error resolving component 'xsd:int'.
It was detected that 'xsd:int' is in namespace 'http://www.w3c.org/2001/XMLSchema',
but components from this namespace are not referenceable from schema document
'file:/C:/.../project/asdfasdf/src/main/resources/RandomObjectSchema.xsd'.
If this is the incorrect namespace, perhaps the prefix of 'xsd:int' needs to be changed.
If this is the correct namespace, then an appropriate 'import' tag should be added to
'file:/C:/.../project/asdfasdf/src/main/resources/RandomObjectSchema.xsd'.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAX
ParseException(ErrorHandlerWrapper.java:203)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Err
orHandlerWrapper.java:134)
File.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3c.org/2001/XMLSchema" targetNamespace="http://asdf.com/asdf">
<xsd:element name="RandomObject">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:int"></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>asdf</groupId>
<artifactId>asdfasdf</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>asdfasdf</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
答案 0 :(得分:2)
您的xsd
命名空间中存在错误。
你有:
http://www.w3c.org/2001/XMLSchema
应该是:
http://www.w3.org/2001/XMLSchema
(www.w3c.org
与www.w3.org
)
错误日志非常详细:
[ERROR] s4s-elt-schema-ns: The namespace of element 'schema' must be from the schema namespace, 'http://www.w3.org/2001/XMLSchema'.
line 2 of file:/.../test.xsd