fmarchioni wrote:
>
>
> fmarchioni wrote:
>> Hi all,
>> I'm trying to generate an XML from a Class file. Since the XML attributes
>> have different name from Java fields I have to use a mapping file.
>> Unfortunately the XML generated stays the same even if I use the mapping
>> file.
>>
>> Simple example:
>>
>> public class Note implements Serializable {
>> long noteId;
>> String actor;
>> // getter and setter methods here
>> }
>>
>> <mapping>
>> <class name="Note">
>> <map-to xml="note" />
>>
>> <field name="actor" type="java.lang.String">
>> <bind-xml name="manager" node="element" />
>> </field>
>> </class>
>> </mapping>
>>
>> So I want in this basic example that the field "actor" is displayed in the
>> XML as "manager".
>>
>> FileWriter writer = new FileWriter("C:\\cds.xml");
>> Note note = getNoteFromDB();
>> Marshaller mar = new Marshaller();
>> mar.setMapping(mapping);
>> mar.marshal(note, writer);
>>
>> Unfortunately the XML generated stays the same, whether or not I use the
>> mapping file....
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <note note-id="6099">
>> <actor>MyBoss</actor>
>> </note>
>>
>> Can anybody help me how to do it ?
>> thanks a lot
>> francesco
>>
>
> sorry I simply tried with:
> Marshaller marshaller = new Marshaller(new
> OutputStreamWriter(System.out));
> marshaller.setMapping(mapping);
> marshaller.marshal(note);
> and now it works...I don't know what was the problem before........
The problem was that you used one of the static marshal() methods that
ignore the mapping you specified completely. See F.A.Q.
Werner
> sorry
> francesco
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email