Reputation: 115
I'm using the org.jvnet plugin and trying to convert an xsd file into a Java Jaxb-annotated object for use in marshalling and unmarshalling. However, there's an error when trying to compile a simple Xsd file for use.
I think there is a simple syntax error I am making, a second look would be really appreciated. If there's any more details I should provide please let me know. All relevant files and messages are included below.
Error message:
[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>
Upvotes: 0
Views: 649
Reputation: 43709
You have a mistake in your xsd
namespace.
You have:
http://www.w3c.org/2001/XMLSchema
It should be:
http://www.w3.org/2001/XMLSchema
(www.w3c.org
vs. www.w3.org
)
The error log is quite verbose about it:
[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
Upvotes: 2