1 /**2 * XmlSerializer XML Serializer3 */4 //Create XmlSerializer5XmlSerializer serializer =Xml.newserializer ();6File File =NewFile (mainactivity. This. Getfilesdir (), "Config +");7 FileOutputStream Fos;8 Try {9FOS =Newfileoutputstream (file);Ten //which file to write the XML file to OneSerializer.setoutput (FOS, "Utf-8"); A //the header of the XML file -Serializer.startdocument ("Utf-8",false); - /** the * nodes are paired, and there's a start that has an end - */ - //the root node of the XML -Serializer.starttag (NULL, "SMSs"); + - for(Smsinfo smsinfo:smsinfos) { + //child Nodes ASerializer.starttag (NULL, "SMS"); at //Properties -Serializer.attribute (NULL, "id", Smsinfo.getid () + ""); - //the first node under a child node -Serializer.starttag (NULL, "Body"); -Serializer.text (Smsinfo.getbody () + ""); -Serializer.endtag (NULL, "Body"); in //second node under a child node -Serializer.starttag (NULL, "Address"); toSerializer.text (smsinfo.getaddress () + ""); +Serializer.endtag (NULL, "Address"); - //the third node under a child node theSerializer.starttag (NULL, "Date"); *Serializer.text (Smsinfo.getdate () + ""); $Serializer.endtag (NULL, "Date");Panax NotoginsengSerializer.endtag (NULL, "SMS"); - } the +Serializer.endtag (NULL, "SMSs"); A serializer.enddocument (); the fos.close (); +Toast.maketext ( This, "Backup succeeded", Toast.length_short). Show (); -}Catch(Exception e) { $ //TODO auto-generated Catch block $ e.printstacktrace (); -Toast.maketext ( This, "Backup Failed", Toast.length_short). Show (); -}
XmlSerializer Generating an XML file