文件名称:三大解析XML
文件大小:4KB
文件格式:TXT
更新时间:2016-11-08 11:25:06
ytuyut
DOM4J创建xml>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Document doc= DocumentHelper.createDocument(); Element e=doc.addElement("email"); e.addElement("from").setText("aaa@aaa.com"); Element to=e.addElement("to"); e.addElement("subject").setText("helle word"); e.addElement("body").setText("hello DOM4J"); to.addElement("to-email").setText("bb@bb.com"); to.addElement("to-email").setText("cc@cc.com"); File sdcard=Environment.getExternalStorageDirectory(); //读取任何设备的根路径 File f1=new File(sdcard,"e1.xml"); File f2=new File(sdcard,"e2.xml"); FileOutputStream out11=new FileOutputStream(f1); FileOutputStream out22=new FileOutputStream(f2); OutputStreamWriter out1=new OutputStreamWriter(out11,"UTF-8"); OutputStreamWriter out2=new OutputStreamWriter(out22,"UTF-8"); XMLWriter writer1=new XMLWriter(out1,OutputFormat.createCompactFormat());//紧凑格式 XMLWriter writer2=new XMLWriter(out2,OutputFormat.createPrettyPrint());//漂亮格式 writer1.write(doc); writer2.write(doc); out1.close(); out2.close();