/**
* 生产xml文件
* @param t
* @param list
* @param encode
* @param fileName
* @author
* @throws Exception
*/
public static <T> void modelToXml(T t,List<T> list,String encode,String fileName) throws Exception{
XMLWriter write=null;
try {
File file=new File(fileName);
if(file.exists()){
file.delete();
}
OutputFormat format=OutputFormat.createPrettyPrint();
format.setEncoding(encode);
Document document=buildDocument(t,list);
write=new XMLWriter(new FileWriter(file),format);
write.write(document);
} catch (Exception e) {
throw new Exception(e);
}finally{
if(null!=write){
try {
write.close();
} catch (IOException e) {
}
}
}
}
/**
* 构建 xml 字符串
* @param t
* @param list
* @return string
* @author
* @throws Exception
*/
public static <T> String modelToXmlStr(T t,List<T> list) throws Exception{
Document document=buildDocument(t,list);
if(null != document){
return document.asXML();
}
* 生产xml文件
* @param t
* @param list
* @param encode
* @param fileName
* @author
* @throws Exception
*/
public static <T> void modelToXml(T t,List<T> list,String encode,String fileName) throws Exception{
XMLWriter write=null;
try {
File file=new File(fileName);
if(file.exists()){
file.delete();
}
OutputFormat format=OutputFormat.createPrettyPrint();
format.setEncoding(encode);
Document document=buildDocument(t,list);
write=new XMLWriter(new FileWriter(file),format);
write.write(document);
} catch (Exception e) {
throw new Exception(e);
}finally{
if(null!=write){
try {
write.close();
} catch (IOException e) {
}
}
}
}
/**
* 构建 xml 字符串
* @param t
* @param list
* @return string
* @author
* @throws Exception
*/
public static <T> String modelToXmlStr(T t,List<T> list) throws Exception{
Document document=buildDocument(t,list);
if(null != document){
return document.asXML();
}