Advertisement
Advertisement
| 07.11.2008 at 01:17AM PDT, ID: 23556474 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: |
//obtaining the XML for transmission
public static String toXML(Object bean) {
String XMLBean = "";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Create XML encoder.
XMLEncoder xenc = new XMLEncoder(baos);
xenc.writeObject(bean);
xenc.flush();
xenc.close();
XMLBean = baos.toString();
return XMLBean;
}
//obtaining object from XML
public static Object fromXML(String XMLBean) {
byte[] buffer = XMLBean.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
// Create XML decoder.
XMLDecoder xdec = new XMLDecoder(bais);
// Read object.
return xdec.readObject();
}
|