users@jaxb.java.net

Re: How to Marshall the parent element

From: James Mao <james.mao_at_iona.com>
Date: Wed, 01 Aug 2007 10:08:49 +0800

After changing the code to JAXBContext jc =
JAXBContext.newInstance(Meta.class);
It just work, Thanks

James

> James Mao wrote:
>> Hi,
>>
>> I have a schema like this,
>>
>> <xs:complexType name="Meta">
>> <xs:sequence> <xs:element name="name"
>> type="xs:string"/>
>> <xs:element name="description" type="xs:string"/>
>> </xs:sequence>
>> </xs:complexType>
>>
>> <xs:complexType name="Store">
>> <xs:complexContent>
>> <xs:extension base="Meta">
>> <xs:sequence>
>> <xs:element name="books" type="Book"
>> minOccurs="1" maxOccurs="unbounded"/>
>> </xs:sequence>
>> </xs:extension>
>> </xs:complexContent>
>> </xs:complexType>
>>
>> <xs:element name="store" type="Store"/>
>> <xs:element name="meta" type="Meta"/>
>>
>>
>>
>> Given the Store object, Is it possible for marshaller to generate the
>> xml which looks like this
>>
>> <meta>
>> <name>my book store>
>> <description> abc </description>
>> </meta>
>
> OK, so you want to marshal Store as Meta? Is that right?
>
> You can do so by creating a JAXBContext just from Meta, thereby
> causing JAXB to treat your Store instances as Meta instances.
>