你的位置:首页 > Java教程

[Java教程]PULL生成XML文件


 1 package  2  3 import java.io.FileNotFoundException; 4 import java.io.FileOutputStream; 5 import java.io.IOException; 6  7 import org. 8 import org. 9 import org.10 11 public class PullProduceDocument {12 13   public static void main(String[] args) throws 14       IllegalStateException, FileNotFoundException, IOException {15 16     // 解析器工厂17      18     // 序列化器19      factory.newSerializer();20     // 设置21     serializer.setOutput(new FileOutputStream("src/books.);22     // 调用序列化器的相关方法向23     serializer.startDocument("UTF-8", true);24     serializer.startTag(null, "books");25     for (int i = 0; i < 5; i++) {26       serializer.startTag(null, "book");27       serializer.attribute(null, "id", "book1");28       serializer.startTag(null, "name");29       serializer.text("三国演义");30       serializer.endTag(null, "name");31       serializer.startTag(null, "author");32       serializer.text("罗贯中");33       serializer.endTag(null, "author");34       serializer.startTag(null, "price");35       serializer.text("30$");36       serializer.endTag(null, "price");37       serializer.endTag(null, "book");38     }39     serializer.endTag(null, "books");40     serializer.endDocument();41 42   }43 44 }