package com.leileixml;
import java.io.FileWriter;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlSerializer;
public class PullSerializae {
public static void main(String[] args) throws Exception {
//创建解析器工厂对象
XmlPullParserFactory parserFactory = XmlPullParserFactory.newInstance();
//2.创建序列化器对象
XmlSerializer serializer = parserFactory.newSerializer();
//3.指定文件存放的路径
serializer.setOutput(new FileWriter("xml2.xml"));
serializer.startDocument("GB2312", false);//文档开始
serializer.startTag(null, "students");//根标记开始
serializer.startTag(null, "student");//student子标记开始
serializer.startTag(null, "xh");//id子标记开始
serializer.text("1234345");//标记内容
serializer.endTag(null, "xh");//id子标记结束
serializer.startTag(null, "name");//name字标记开始
serializer.text("阿拉蕾");
serializer.endTag(null, "name");//name子标记结束
serializer.startTag(null, "age");//age字标记开始
serializer.text("19");
serializer.endTag(null, "age");//age子标记结束
serializer.startTag(null, "sex");//sex子标记开始
serializer.text("女");
serializer.endTag(null, "sex");//sex子标记结束
serializer.endTag(null, "student");//student子标记结束
serializer.startTag(null, "student");
serializer.attribute(null, "xh", "1314520");//命名空间、属性名、属性值
serializer.attribute(null, "name", "王明雷");//命名空间、属性名、属性值
serializer.attribute(null, "age", "26");//命名空间、属性名、属性值
serializer.attribute(null, "sex"," 男");//命名空间、属性名、属性值
serializer.endTag(null, "student");
serializer.endTag(null, "students");
serializer.endDocument();
}
}