Java examples for XML:DOM Element
encode Object to XML Element
//package com.java2s; import java.lang.reflect.Field; import org.w3c.dom.Element; public class Main { public static void encodeObject(Object object, Element node) { Class classObject = object.getClass(); Field[] fields = classObject.getFields(); for (Field field : fields) { try { String name = field.getName(); Object value = field.get(object); node.setAttribute(name, String.valueOf(value)); } catch (IllegalArgumentException e) { e.printStackTrace();/*from ww w .java 2s .co m*/ } catch (IllegalAccessException e) { e.printStackTrace(); } } } }