You
basically want to use a structure element with a field attribute to
represent the fact that you have a java structure that is going to flattened in
the XML (as with the field bar). And a structure element with a name attribute
to show that you have an XML structure that will be flattened in java (as with
the name element with a nested name attribute).
Binding:
<binding>
<mapping name="Foo" class="Foo">
<structure field="bar">
<structure name="name" value-style="element">
<value name="name" field="name" style="attribute"/>
</structure>
<collection field="value">
<structure name="value" value-style="element">
<value name="val" style="attribute"/>
</structure>
</collection>
</structure>
</mapping>
</binding>
<mapping name="Foo" class="Foo">
<structure field="bar">
<structure name="name" value-style="element">
<value name="name" field="name" style="attribute"/>
</structure>
<collection field="value">
<structure name="value" value-style="element">
<value name="val" style="attribute"/>
</structure>
</collection>
</structure>
</mapping>
</binding>
Output:
<?xml version="1.0"
encoding="UTF-8"?>
<Foo>
<name name="aaa"/>
<value val="bbb"/>
<value val="ccc"/>
</Foo>
<Foo>
<name name="aaa"/>
<value val="bbb"/>
<value val="ccc"/>
</Foo>
References:
Mocky
-----Original Message-----Hi friends,
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Z.S.
Sent: Wednesday, August 03, 2005 3:48 AM
To: [email protected]
Subject: [jibx-users] One problem on writing the binding xml
Recently I met a problem on writing the binding xml file.
the classes:
===============================
public class Bar {
public String name;
public ArrayList value;
public String getName(){
return name;
}
public void setName(String a){
name = a;
}
public ArrayList getValue(){
return value;
}
public void setValue(ArrayList a){
value = a;
}
}
public class Foo {
private Bar bar;
public Foo();
public getBar() {
return bar;
}
public void setBar(Bar bar) {
this.bar = bar;
}
}
==================================
the format of output xml I want is like this:
<Foo>
<name name="aaa"/>
<value val="bbb"/>
<value val="ccc"/>
</Foo>
rather than:
<Foo>
<Bar>
<name name="aaa"/>
<value>
<value val="bbb"/>
<value val="ccc"/>
<value>
</Bar>
</Foo>
how can I wirte the binding?
Many thanks for your help:)
ZS
