users@jaxb.java.net

Re: marshal lists - missing type names

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Tue, 9 Sep 2008 10:17:54 +0200

To make JAXB insert the missing element levels, you'll have to define
intermediary levels of xsd:complexType. For instance, the element
<Trades> (in BusinessEvent) will have to have type="TradesType", and
*this* one should be defined to have a repeatable element IIdentifier.
You'll need an additional level of element creation to compose the
content tree..

HTH
Wolfgang


On Tue, Sep 9, 2008 at 5:39 AM, uberdog <jay_at_4st.org> wrote:
>
> I had a similar problem and solved it by removing an interface I had the
> class implementing.
>
>
>
> eddy eldridge wrote:
>>
>> hi, i'm using jaxb to generate xml from classes generated from a schema
>> using xjc. the xml has to work on both .net and java for interoperability.
>> there are 2 xml snippets below. the first is the output from .net and the
>> second is from jaxb. jaxb misses out the type names of the list elements.
>> The type names are IIdentifier and BusinessEvent. The .net generation adds
>> them, but the jaxb doesn't. is this a bug or hopefully something i am
>> doing wrong. The relevant part of the schema is at the bottom. the java
>> code from the unit test is directly below:-
>>
>> // create the context for the deal type
>>
>> JAXBContext context = JAXBContext.newInstance(DealImpl.class);
>>
>> // create a deal for unit test
>> Deal deal = createCannedDeal(); Marshaller m = context.createMarshaller();
>> m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); StringWriter swNew
>> = new StringWriter(); m.marshal(deal, swNew);
>>
>> // microsoft xml xnippet
>> <BusinessEvents>
>> <BusinessEvent>
>> <EventType>
>> <Id>
>> <Id>be1</Id>
>> </Id>
>> <Name>BE name1</Name>
>> </EventType>
>> <Trades>
>> <IIdentifier>
>> <Id>trade1</Id>
>> </IIdentifier>
>> <IIdentifier>
>> <Id>trade2</Id>
>> </IIdentifier>
>> </Trades>
>> </BusinessEvent>
>> <BusinessEvent>
>> <EventType>
>> <Id>
>> <Id>be2</Id>
>> </Id>
>> <Name>BE name2</Name>
>> </EventType>
>> </BusinessEvent>
>> </BusinessEvents>
>>
>> // jaxb xml snipper
>> <BusinessEvents>
>> <EventType>
>> <Id>
>> <Id>be1</Id>
>> </Id>
>> <Name>BE name1</Name>
>> </EventType>
>> <Trades>
>> <Id>trade1</Id>
>> </Trades>
>> <Trades>
>> <Id>trade2</Id>
>> </Trades>
>> </BusinessEvents>
>> <BusinessEvents>
>> <EventType>
>> <Id>
>> <Id>be2</Id>
>> </Id>
>> <Name>BE name2</Name>
>> </EventType>
>> </BusinessEvents>
>>
>>
>> // schema snippet
>>
>>
>> <xs:complexType name="IIdentifier">
>> <xs:sequence>
>> <xs:element name="Id" type="xs:string" minOccurs="0"/>
>> </xs:sequence>
>> </xs:complexType>
>>
>> <xs:complexType name="BaseIdentifier" abstract="true" mixed="false">
>> <xs:complexContent mixed="false">
>> <xs:extension base="IIdentifier"/>
>> </xs:complexContent>
>> </xs:complexType>
>>
>>
>> <xs:complexType name="Deal">
>> <xs:sequence>
>> <xs:element name="BusinessEvents" type="BusinessEvent" minOccurs="0"
>> maxOccurs="unbounded"/>
>> </xs:sequence>
>> </xs:complexType>
>>
>> <xs:complexType name="BusinessEvent">
>> <xs:sequence>
>> <xs:element name="EventType" type="BusinessEventType"/>
>> <xs:element name="Trades" type="IIdentifier" minOccurs="0"
>> maxOccurs="unbounded"/>
>> </xs:sequence>
>> </xs:complexType>
>>
>> <xs:complexType name="BusinessEventType">
>> <xs:sequence>
>> <xs:element name="Id" type="BusinessEventCode"/>
>> <xs:element name="Name" type="xs:string"/>
>> </xs:sequence>
>>
>> <xs:complexType name="BusinessEventCode" mixed="false">
>> <xs:complexContent mixed="false">
>> <xs:extension base="BaseIdentifier"/>
>> </xs:complexContent>
>>
>>
>>
>>
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/marshal-lists---missing-type-names-tp17204396p19385327.html
> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>