58,454
社区成员
发帖
与我相关
我的任务
分享
package otx.pzxml;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import otx.consvr.consqlsvr;
public class toxml {
public toxml(String ywdybh,String ywczy,String pzf,String pzt) {
String strsql="";
consqlsvr sqlconn=null;
ResultSet pzlbrst=null;
ResultSet pzrst=null;
ResultSet pzflrst=null;
XMLWriter writer =null;
try {
OutputFormat xmlformat = OutputFormat.createPrettyPrint();
xmlformat.setEncoding("UTF-8");
xmlformat.setLineSeparator("\n");
xmlformat.setTrimText(false);
xmlformat.setNewlines(true);
xmlformat.setIndent(" ");
……省略创建XML节点代码......
File file1=new File(".\\"+ywdybh);
if (!file1.exists() &&!file1.isDirectory())
file1.mkdir();
writer = new XMLWriter(new FileWriter(".\\"+ywdybh+"\\"+ywdybh+".xml"),xmlformat);
writer.write(document);
writer.close();
JOptionPane.showMessageDialog(null,"生成XML文件成功!", "系统信息", JOptionPane.INFORMATION_MESSAGE);
pzlbrst.close();
} catch (IOException e) {
pzflrst=null;
pzrst=null;
pzlbrst=null;
e.printStackTrace();
} catch (SQLException e) {
pzflrst=null;
pzrst=null;
pzlbrst=null;
e.printStackTrace();
} finally {
writer=null;
pzflrst=null;
pzrst=null;
pzlbrst=null;
sqlconn=null;
}
}
}