https://youtu.be/2IatWH5EQQA?t=23m13s
android視頻教程 29 xml文件的序列化
public class XmlnewSerializer {
private Context context;
public XmlnewSerializer(Context context) {
this.context = context;
}
public void create() throws Exception {
XmlSerializer xmlSerializer = Xml.newSerializer();
CharArrayWriter temp = new CharArrayWriter();
ByteArrayOutputStream temp2 = new ByteArrayOutputStream();
xmlSerializer.setOutput(temp2, "utf-8");
xmlSerializer.startDocument("utf-8", true);
xmlSerializer.startTag(null, "test");
for (int i = 0; i < 5; i++) {
xmlSerializer.startTag(null, "book");
xmlSerializer.attribute(null, "id", i + "");
xmlSerializer.startTag(null, "author");
xmlSerializer.text("Gambardella, Matthew");
xmlSerializer.endTag(null, "author");
xmlSerializer.endTag(null, "book");
}
xmlSerializer.endTag(null, "test");
xmlSerializer.endDocument();
System.out.println(temp);
FileOutputStream fs = context.openFileOutput("newxml.xml", Context.MODE_PRIVATE);
fs.write(temp2.toByteArray());
fs.close();
}
}
0 件のコメント:
コメントを投稿