Generating an XML file
- Create a few virtual SMS objects that exist in list
- Backup data is usually backed up to an SD card
Use StringBuffer to stitch strings
append all the nodes of the XML file into SB object
sb.append ("<?xml version= ' 1.0 ' encoding= ' utf-8 ' standalone= ' yes '?> ');//Add SMSS Start node sb.append (" <smss> " );.......
Write SB into the output stream
fos.write(sb.toString().getBytes());
To generate an XML file using an XML serializer
Get the XML Serializer object
xmlserializer xs = Xml.newserializer ();
Set the output stream to the serializer
File file = new File(Environment.getExternalStorageDirectory(), "backupsms.xml");FileOutputStream fos = new FileOutputStream(file);//给序列化器指定好输出流xs.setOutput(fos, "utf-8");
To start generating an XML file
xs.startDocument("utf-8", true);xs.startTag(null, "smss");xs.endTag(null, "smss"); ...... xs.endDocument();
To generate an XML file using an XML serializer