commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Low Han Ming" <low_hanm...@yahoo.com.sg>
Subject [Betwixt] Help : Writing collection of objects to sub element instead of attribute
Date Thu, 03 Apr 2008 13:24:54 GMT
Hi,
 
I'm new to Betwixt.
I would really appreciate if someone can advice on how to output a
collection of custom class of object into a sub element in the XML instead
of attribute.
 
I would like my output to be 

<?xml version='1.0' ?>
<person name="John Smith">
  <items>
    <Item><id>a</id></Item>
    <Item><id>b</id></Item>
  </items>
</person>

But instead, the output was 

<?xml version='1.0' ?>
<person name="John Smith">
  <items>
    <Item id="a"/>
    <Item id="b"/>
  </items>
</person>

The main difference is the "id" under <item> being an attribute instead of
an element.

I greatly appreciate if you can advise or point me to some sample that can
do the job.
 

Thanks.
 

Han Ming

 

 

Code
########################################################
PersonBean
public class PersonBean {
private String name;
ArrayList items;

public ArrayList getItems() {return items;}
public void setItems(ArrayList items) {this.items = items;}

public String getName() {return name;}
public void setName(String name) {this.name = name;} 

}

 
Item 
public class Item {
String id;

public String getId() {return id;}
public void setId(String id) {this.id = id;}
}

 
main class .....
PersonBean person = new PersonBean();
person.setName("John Smith");

ArrayList items = new ArrayList();

Item item1 = new Item();
item1.setId("a");

Item item2 = new Item();
item2.setId("b");

items.add(item1);
items.add(item2);

person.setItems(items);

 




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message