users@jaxb.java.net

Re: How to Marshall the parent element

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Tue, 31 Jul 2007 09:15:05 -0700

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.

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com