i solved this by using xstream but please tell me the below code will assist for more object expenses
i thought of using iteration on wherever required required
import java.util.List;
import java.util.ArrayList;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
public class ChartUtil
{
public static void main(
String[] args)
{
XStream xstream = new XStream();
Chart oChart = new Chart();
oChart.setCaption("Model Comparison");
Category oCategory = new Category();
oCategory.setLabel("Lot Quantity");
oChart.addCategories(oCategory);
oCategory = new Category();
oChart.setCaption("Total Cost");
oChart.addCategories(oCategory);
Dataset oDataset = new Dataset();
oDataset.setSeriesName("Lot Quantity");
Set oSet = new Set("100");
oDataset.addSet(oSet);
oDataset.addSet(oSet);
oSet = new Set("101");
oDataset.addSet(oSet);
oSet = new Set("102");
oChart.addDataSet(oDataset);
oDataset = new Dataset();
oDataset.setSeriesName("Total Cost");
oSet = new Set("100");
oDataset.addSet(oSet);
oSet = new Set("101");
oDataset.addSet(oSet);
oSet = new Set("102");
oDataset.addSet(oSet);
oChart.addDataSet(oDataset);
xstream.addImplicitCollection(Chart.class, "dataSet");
xstream.autodetectAnnotations(true);
System.out.println(xstream.toXML(oChart));
}
}
@XStreamAlias("Chart")
class Chart
{
@XStreamAsAttribute
private String caption;
private List<Category> categories = new ArrayList<Category>();
private List<Dataset> dataSet = new ArrayList<Dataset>();
private List<Set> set = new ArrayList<Set>();
public Chart()
{
}
public void addCategories(Category ocategory) {
categories.add(ocategory);
}
public void addDataSet(Dataset oDataset) {
dataSet.add(oDataset);
}
public void addSet(Set oSet) {
set.add(oSet);
}
public void setCaption(String caption) {
this.caption = caption;
}
public String getCaption() {
return caption;
}
}
@XStreamAlias("category")
class Category
{
@XStreamAsAttribute
private String label;
Category()
{
}
public void setLabel(String label) {
this.label = label;
}
public String getLabel() {
return label;
}
}
@XStreamAlias("dataset")
class Dataset
{
private List<Set> set = new ArrayList<Set>();
@XStreamAsAttribute
private String seriesName;
Dataset()
{
}
public void addSet(Set oSet)
{
set.add(oSet);
}
public String getSeriesName() {
return seriesName;
}
public void setSeriesName(String seriesName) {
this.seriesName = seriesName;
}
}
@XStreamAlias("set")
class Set
{
@XStreamAsAttribute
private String value;
Set(String valueLocal)
{
this.value = valueLocal;
}
public void setValue(String value)
{
this.value = value;
}
public String getValue()
{
return value;
}
}