Hi all,
I want to use Castor to generate XML files form my objects. One attribute of my class has a List type.
In my resulting file I get rows like :
<item xsi:type="java:entites.OrderItem"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">I'd like
<item>Here is my example :
====================
Order class
====================
public class Order {
private int id;
private List items; public Commande() {}
public Commande(int id) {this.id = id; }
public List getItems() {return items;}
public void setItems(List items) {this.items = items;}
}====================
OrderItem class
====================
public class OrderItem {
private String id; public LigneCommande() {super();}
public LigneCommande(int id) {this.id = id; }
public String getId() {return id;}
public void setId(String string) {id = string;}
}====================
Mapping file
====================
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
"http://castor.exolab.org/mapping.dtd">
<mapping>
<description>Mapping Order Class</description> <class name="entites.Order" auto-complete="yes">
<map-to xml="order"/>
<field name="items">
<bind-xml name="item" location="items" />
</field>
</class>
</mapping>
==================== Test class ==================== public class TestXMLOrder {
final private static String BASE_DIR = "src/castor";
public static void main(String[] args) {
FileWriter writer = null;
Marshaller marshaller = null; Order o = new Order(1);
List rows= new ArrayList();
rows.add(new OrderItem("Item1"));
rows.add(new OrderItem("Item2"));
rows.add(new OrderItem("Item3"));
o.setItems(rows);
try {
writer = new FileWriter( BASE_DIR + "/order-output.xml");
Mapping map = new Mapping();
marshaller = new Marshaller(writer);
try {
map.loadMapping("src/order.xml");
marshaller.setMapping(map);
marshaller.marshal(o);
} catch (MappingException e1) {
e1.printStackTrace();
} } catch (IOException e) {
e.printStackTrace();
} catch (MarshalException e) {
e.printStackTrace();
} catch (ValidationException e) {
e.printStackTrace();
}} }
====================
Resulting file
====================
<?xml version="1.0" encoding="UTF-8"?>
<order>
<items>
<item xsi:type="java:entites.OrderItem"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<id>Item1</id>
</item>
<item xsi:type="java:entites.OrderItem"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<id>Item2</id>
</item>
<item xsi:type="java:entites.OrderItem"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<id>Item3</id>
</item>
</items>
</order>======================
Resulting wanted file
======================
<?xml version="1.0" encoding="UTF-8"?>
<order>
<items>
<item>
<id>Item1</id>
</item>
<item>
<id>Item2</id>
</item>
<item>
<id>Item3</id>
</item>
</items>
</order>Can anybody tell me if this is possible and how to do ?
Regards
-- A. ROY
----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user
