Android--write XML to SD card

Source: Internet
Author: User

Information class

Private String body; Private String number; Private int type; Private long ID;

Four variables, then set and get respectively. The constructor initializes these four variables separately.

Generating XML tag functions

 Public Static voidBackupxml (file file, list<xmlinfo> Smsinfos)throwsException {//the sequence number of the XML file helps generate an XML fileFileOutputStream fos =Newfileoutputstream (file); //Gets the sequence number to the XMLXmlSerializer serializer =Xml.newserializer (); //Serialization InitializationSerializer.setoutput (FOS, "Utf-8"); //Creating XMLSerializer.startdocument ("Utf-8",true); Serializer.starttag (NULL, "SMSs");  for(Xmlinfo Info:smsinfos) {Serializer.starttag (NULL, "SMS"); Serializer.attribute (NULL, "id", String.valueof (Info.getid ())); Serializer.starttag (NULL, "Body"); Serializer.attribute (NULL, "Body", Info.getbody ()); Serializer.endtag (NULL, "Body"); Serializer.starttag (NULL, "number");            Serializer.text (Info.getnumber ()); Serializer.endtag (NULL, "number"); Serializer.endtag (NULL, "SMS"); } Serializer.endtag (NULL, "SMSs");                Serializer.enddocument ();        Fos.flush ();        Fos.close (); }

Processing in OnCreate

List<xmlinfo> Xmlinfo =NewArraylist<xmlinfo>(); Xmlinfo XML1=NewXmlinfo ("AAAA", "12345678912",); Xmlinfo XML2=NewXmlinfo ("bbbb", "21987654321",); Xmlinfo XML3=NewXmlinfo ("CCCC", "12345678912", 1,3);        Xmlinfo.add (XML1);        Xmlinfo.add (XML2);                        Xmlinfo.add (XML3); File File=NewFile (Environment.getexternalstoragedirectory (), "Back.xml"); //File File = new file (MainActivity.this.getFilesDir (), "Back.xml");        Try{xmlmanager.backupxml (file, xmlinfo); Toast.maketext ( This, "Backup succeeded", 0). Show (); } Catch(Exception e) {//TODO Auto-generated catch blockE.printstacktrace (); Toast.maketext ( This, "Backup Failed", 0). Show (); }

I'm the dividing line of the king of the Land Tiger.

Source code: HTTP://PAN.BAIDU.COM/S/1DD1QX01

XML common parsing. zip

Reprint Please specify source: Http://www.cnblogs.com/yydcdut

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.