Hi,

daab wrote:
> 
> Werner Guttmann wrote:
>> How do these objects relate to each other ? Are they part of e.g. an
>> inheritance hierarchy ? Will each of those objects be mapped ?
>>
> Originally, they weren't part of a hierarchy.
But they are now, correct ?

> What I ended up trying was
> the example on the castor homepage where a hashtable of objects was wrapped
> inside a class and that that class would be written.  I couldn't get this to
> work though.
Why not ? Have you seen the HOW-To that shows you how to map a Map of
objects to XML ? This is a recipe that has been tried before it has been
written.

> 
> 
> Werner Guttmann wrote:
>> Hi,
>>
>> can you define the term 'multiple objects' for us ?
>>
>> Werner
>>
> I mean a sequence of objects.  They have a list of authors within the book
> object they marshal, so I suppose technically they cover it.  In this case,
> I'd want to do multiple books.
> 
> In the end what has worked for me is:
> http://www.castor.org/how-to-map-a-list-at-root.html
> The setRootElement method is very useful.  This is what I am doing now:
>     try {
>         //Create list from hashtable
>         List myObjectList = new LinkedList();
>         Enumeration keySetNumeration = myObjectTable.keys();
>         while(keySetNumeration.hasMoreElements()) {
>            
> myObjectList.add(myObjectTable.get(keySetNumeration.nextElement()));
>         }
>         
>         //Preparing writer
>         BufferedWriter theBufferedFileWriter = new BufferedWriter(new
> FileWriter("output.xml"));
>         StringWriter theStringWriter = new StringWriter();
> 
>         //Preparing marshaller
>         Marshaller m = new Marshaller();
>         Mapping mapping = new Mapping();
>         mapping.loadMapping("mapping.xml");
>         m.setMapping(mapping);
>         m.setWriter(theStringWriter);
>         m.setRootElement("rootObject");
>         m.marshal(myObjectList);
> 
>         //Writing XML file
>         theBufferedFileWriter.write(theStringWriter.toString());
>         theBufferedFileWriter.close();
>         theStringWriter.close();
>     } catch (Exception e) {
>         System.err.println(e.getMessage());
>         e.printStackTrace(System.err);
>     }
> 
> So my problem is solved for now :)
Okay.
> 

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to