users@jaxb.java.net

Re: Unmarshalling complex types (without global elements) in JAXB1

From: Felipe Gaścho <fgaucho_at_gmail.com>
Date: Mon, 21 Jan 2008 20:04:51 +0100

very nice......


I am day after day becoming against "XML without Model", like these
fragments... but the hack is perfect :)

On Jan 21, 2008 7:19 PM, Aleksei Valikov <valikov_at_gmx.net> wrote:
> Hi.
>
> I've finally managed to solve the problem I've been having for a long
> time already.
>
> The task is about unmarshalling complex types from XML fragments.
> Imagine we have a complex type like this one:
>
> <xsd:complexType name="CI_ResponsibleParty">
> <xsd:sequence>
> <xsd:element name="individualFirstName" type="base:CharacterString"
> minOccurs="0" ref:id="375"/>
> <xsd:element name="individualLastName" type="base:CharacterString"
> minOccurs="0" ref:id="375"/>
> <xsd:element name="organisationName" type="base:CharacterString"
> minOccurs="0" ref:id="376"/>
> <xsd:element name="positionName" type="base:CharacterString"
> minOccurs="0" ref:id="377"/>
> <xsd:element name="contactInfo" type="base:CI_Contact"
> minOccurs="0" ref:id="378"/>
> </xsd:sequence>
> </xsd:complexType>
>
> Assume we don't have a global element for this type. The question (or
> task) is - how to unmarshall an instance of this type from an XML
> fragment like this:
>
> <any uuid="12" xmlns="http://www.disy.de/preludio2/base">
> <individualFirstName>none</individualFirstName>
> <positionName>test</positionName>
> <contactInfo>
> <hoursOfService>10-16</hoursOfService>
> </contactInfo>
> </any>
>
> Name of the root element is not important. JAXB1 can't unmarshal this
> fragment without global element, so even if you know which type is
> being unmarshalled, you can't do it with standard API. Typical task
> is: you'd like to load a part of your object structure from XML, but
> there's no global element for the corresponding complex type.
>
> With this mail, I wanted to share my solution. Source code is attached.
>
> Bye.
> /lexi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>