Re: [Simple-support] Serializing inline list of "simple" elements
Brought to you by:
niallg
|
From: Kevin J. <kjo...@in...> - 2008-05-30 06:18:54
|
this works great - thanks!
-kevin
On May 28, 2008, at 12:01 AM, Timo Rumland wrote:
> Hi Kevin,
>
> the following code produces exactly the result you desire:
>
> ----------------------------
>
> public class SimpleXMLTest {
>
> @Root
> private class Event {
>
> @Text
> private String text;
>
> public Event( String text ) {
> this.text = text;
> }
>
> public String getText() {
> return text;
> }
> }
>
> @Root( name = "events" )
> private class EventList {
>
> @ElementList( inline = true )
> private List< Event > events = new ArrayList< Event >();
>
> public List< Event > getEvents() {
> return events;
> }
> }
>
> public SimpleXMLTest() throws Exception {
>
> EventList list = new EventList();
>
> list.getEvents().add( new Event( "foo" ) );
> list.getEvents().add( new Event( "bar" ) );
>
> Serializer serializer = new Persister();
> serializer.write( list, System.out );
> }
>
> public static void main( String[] args ) throws Exception {
> new SimpleXMLTest();
> }
> }
> ----------------------------
>
>
> Please have a look at the "name" and "inline" annotation parameters -
> these control the "format" of the XML, so it looks like your XML
> example.
>
>
> Hope that helps
>
>
> Regards,
> Timo
>
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Simple-support mailing list
> Sim...@li...
> https://lists.sourceforge.net/lists/listinfo/simple-support
|