Thanks for the reply. I've modified the files and attached the xsd,
xjb and sample test file.
The Common.xsd and Common.xjb is in dir libObject1. Main.xsd and
Main.xjb is in dir libObject2.
The namespace in common.xsd is
http://www.w3.org/2001/XMLSchema,
because i was getting Adapter1 error, which it was trying to reference
from w3. I used this link to fix it.
https://jaxb.dev.java.net/guide/Customizing_Java_packages.html#Tip__get_rid_of_the_org_w3__2001_xmlschema_package
I'll also try out the validation. Let me know if i could give
additional information.
Regards,
Jyoti
On Tue, Jun 16, 2009 at 2:56 PM, Wolfgang Laun<wolfgang.laun_at_gmail.com> wrote:
> Most likely you have a problem with namespace definition in
> the schema and/or the unmarshalled XML data.
>
> I'd need to see the exact and complete (or consistently modified) <schema>
> elements in both schema files, the <import> element, the exact names
> you use in your type definitions and type references, and the XML data
> snippet for an element of type "object2".
>
> You can check the compliance of your XML data by requesting
> validation against the schema; for this, consult the JAXB tutorial
>
> -W
>
> On 6/16/09, jyoti chhabra <jyoti.chhabra_at_gmail.com> wrote:
>>
>> 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>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>>
>
>
- application/octet-stream attachment: Main.xjb
- application/octet-stream attachment: Main.xsd