users@jaxb.java.net

Unmarshal issue with xs:import

From: jyoti chhabra <jyoti.chhabra_at_gmail.com>
Date: Tue, 16 Jun 2009 14:18:31 +0530

Hey,

I am using Jaxb 2.1. I have 2 xsd's Main.xsd and Common.xsd. In
Main.xsd i am using xs import for common.xsd and using one of the it's
complex types.
When i call unmarshal, it makes object2 which does have object1, but
all the elements in object1 are null. Even thought i am passing the
information.

Does Jaxb gets object information from import fields? Is there any
special setting for it to work?

Let me know if i could give any additional information. I've copied
snippets from java code and xsd file.

Regards,
Jyoti

Java code
JAXBContext jc = JAXBContext.newInstance(Object2.class.getPackage().getName());
Unmarshaller jaxbUnmarshaller = jc.createUnmarshaller();
JAXBElement<Object2> jaxbElement  =
(JAXBElement<Object2>)getUnmarshaller().unmarshal(
                               new StreamSource( new StringReader
(messageContents))); //
messageContents is string
Object2 myObject = jaxbElement.getValue();
----
Common.xsd
<xs:complexType name="object1">
<xs:sequence>
<xs:element name="id" type="xs:int"/>
<xs:element name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
----
Main.xsd
xmlns:common=<common xsd name space>
<xs:import namespace=<common xsd name space> schemaLocation="Common.xsd"/>
<xs:complexType name="object2>
<xs:sequence>
<xs:element name="id" type="xs:int"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="object1" type="common:object1"/>
</xs:sequence>
</xs:complexTypes>