users@jaxb.java.net

Re: Unmarshal issue with xs:import

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Tue, 16 Jun 2009 11:26:47 +0200

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<https://jaxb.dev.java.net/tutorial/section_3_3-Validation.html#Validation>

-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
>
>