hi Birgit
though you can mix digester rules with betwixt, this is an advanced topic. i'd suggest that you'd be better letting betwixt do the whole of your mapping initially.
if you want to vary your mapping of beans into elements, i'd suggest reading up on dot betwixt files.
- robert
On 17 Aug 2004, at 10:13, Birgit Linner wrote:
Hi everybody!
I`m new to betwixt and want to use it to dump and import our database
tables.
Dumping is ok, altough I have some questions, too.
The problem is, that every reference to other objects is null when I read
the XML file.
( I have defined: beanReader.getBindingConfiguration().setMapIDs(true); )
I have the following structure in the XML File:
----------------------- dump.xml ---------------------------------- <ArrayList> <ArrayList> <Person id="1"..... /> ... </ArrayList> ... <ArrayList> <Projekt id="12"...> <manager idref="13"/> --> Reference to Person </Projekt> </ArrayList> ---------------------------------------------------------------------
I am reading the XML file with this Reader (btw: I`m also new to Digester
and tried a bit to get the ArrayList structure out of the file, I got no
result when only using beanReader.registerBeanClass(...) ):
-------------------- Dumper.java ------------------------------------
StringReader xmlReader = new StringReader("dump.xml");
BeanReader beanReader = new BeanReader();
beanReader.getXMLIntrospector().setWrapCollectionsInElement(false);
beanReader.getXMLIntrospector().setAttributesForPrimitives(true);
beanReader.getBindingConfiguration().setMapIDs(true);
beanReader.registerBeanClass("ArrayList", ArrayList.class);
beanReader.addObjectCreate("ArrayList/ArrayList", ArrayList.class);
beanReader.addSetNext("ArrayList/ArrayList", "add");
beanReader.registerBeanClass("ArrayList/ArrayList/Person", Person.class);
beanReader.addSetNext("ArrayList/ArrayList/Person", "add");
beanReader.registerBeanClass("ArrayList/ArrayList/Role", Role.class);
beanReader.addSetNext("ArrayList/ArrayList/Role", "add");
beanReader.registerBeanClass("ArrayList/ArrayList/Arbeitszeit",
Arbeitszeit.class);
beanReader.addSetNext("ArrayList/ArrayList/Arbeitszeit", "add");
beanReader.registerBeanClass("ArrayList/ArrayList/Projekt", Projekt.class);
beanReader.addSetNext("ArrayList/ArrayList/Projekt", "add");
Object result = beanReader.parse(new File("dump.xml"));
----------------------------------------------------------------------- -
With this configuration I get an ArrayList with ArrayLists.. and so on, but - how mentioned above - the idref is null:
---------------------- OUTPUT ----------------------------------------- Projekt: id ="0" manager=null name ="Projekt1" -----------------------------------------------------------------------
Is there anything I forgot? Or am I doing something wrong? I`d really appreciate a tip!
Another question about wrinting a bean to XML:
I`d like to rename my ArrayLists (only for better reading), e.g. the
root-ArrayList to "Data" and the inner ones to "persons", "project" etc.
Is this possible? I tried, but always get empty tags (also with using
class-property in element-tag). But this is only "nice to have"...
Thanks in advance!
Have a nice day!
Birgit
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
