users@jaxb.java.net

Marshal/unmarshal contained objects

From: <bhaddow_at_orbism.com>
Date: Wed, 24 Sep 2003 17:07:17 +0100

Hi

I have a schema definition as follows (some elements omitted for clarity).

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
    <xs:element name="alarm_profile">
        <xs:complexType>
            <xs:sequence>
                <!-- several elements -->
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="alarm_profile_list">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="alarm_profile" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

I unmarshal an xml document containing an alarm_profile_list and this gives
me an AlarmProfileList object. Calling getAlarmProfile() on this list object
gives me a List of AlarmProfileType objects. I'd like to take one of the
AlarmProfileType objects and marshal it out as an xml document, however the
resulting document contains no root element. I'd like the marshalled version
of AlarmProfileType to contain the <alarm_profile></alarm_profile> tags, is
this possible?

JAXBContext jc = JAXBContext.newInstance(contextName);
Unmarshaller u = jc.createUnmarshaller();
InputStream is = ....
AlarmProfileList profileList =
            (AlarmProfileList)u.unmarshal(is);
AlarmProfileType profile =
        (AlarmProfilerType)profileList.getAlarmProfile().get(0);
Marshaller m = jc.createMarshaller();
StringWriter out = new StringWriter();
m.marshal(profile,out);


thanks
Barry

-------------------------------------------------------

-------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net