XmlSerializer Generating an XML file

Source: Internet
Author: User

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

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.