java 对象与xml相互转换

https://blog.csdn.net/u012881904/article/details/65448822
http://www.uziot.com/article/1396
 

 

public static void toXml(XmlExportOutPut xmlExportOutPut, FileOutputStream fileOutputStream) throws IOException{
    String dec = getDeclaration();
    byte[] bytesOfDec = dec.getBytes("UTF-8");
    fileOutputStream.write(bytesOfDec);
    XStream stream =new XStream();
    stream.alias("config",XmlExportOutPut.class);
    stream.alias("section", XmlPersonOutput.class);
    stream.aliasAttribute(XmlPersonOutput.class,"id","id");
    stream.aliasAttribute(XmlPersonOutput.class,"name","name");
    stream.aliasAttribute(XmlPersonOutput.class,"sex","sex");
    stream.aliasAttribute(XmlPersonOutput.class,"tel","tel");
    stream.aliasAttribute(XmlPersonOutput.class,"cardid","cardid");
    stream.aliasAttribute(XmlPersonOutput.class,"cardtype","cardtype");
    stream.aliasAttribute(XmlPersonOutput.class,"nationality","nationality");
    stream.aliasAttribute(XmlPersonOutput.class,"age","age");
    stream.aliasAttribute(XmlPersonOutput.class,"picpath","picpath");
    stream.aliasAttribute(XmlPersonOutput.class,"ex","ex");
    stream.addImplicitArray(XmlExportOutPut.class,"xmlPersonOutputs");
    stream.toXML(xmlExportOutPut,fileOutputStream);
}

 

上一篇:Java学习 day16 File&IO


下一篇:Android APK打包并防反编译