Object -> XML 문자열 변환
아주 간단하게 처리 된다.
아주 간단하게 처리 된다.
import java.io.StringWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.betwixt.io.BeanWriter; public class WriteExampleApp { public static final void main(String [] args) throws Exception { StringWriter outputWriter = new StringWriter(); outputWriter.write(""); BeanWriter beanWriter = new BeanWriter(outputWriter); // Bean 속성 으로 값 출력 여부 beanWriter.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(true); // 아이디 출력 여부 beanWriter.getBindingConfiguration().setMapIDs(false); // 정렬 beanWriter.enablePrettyPrint(); List list1 = new ArrayList(); list1.add(new PersonBean("hk", 20)); list1.add(new PersonBean("dk", 20)); Map map = null; List list2 = new ArrayList(); map = new HashMap(); map.put("name", "hk"); map.put("age", "20"); list2.add( map ); map = new HashMap(); map.put("name", "dk"); map.put("age", "20"); list2.add( map ); beanWriter.write("list1", list1); beanWriter.write("list2", list2); System.out.println(outputWriter.toString()); outputWriter.close(); } }
[참조] http://commons.apache.org/betwixt/guide/examples.html