How Android generates XML file data

Source: Internet
Author: User

Note that you need to set the SD card permissions here

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/54/6D/wKiom1SBwW-xDhQgAACasQh6_Cc145.jpg "title=" QQ picture 20141205223036.jpg "alt=" Wkiom1sbww-xdhqgaacasqh6_cc145.jpg "/>


public void OnClick (View arg0) {

Creating objects that serialize XML data

XmlSerializer Xml=xml.newserializer ();

Create a target file object

File file= new file (Environment.getexternalstoragedirectory (), "Stuinfo");

Creating a document output stream object

FileOutputStream Fos=null;

try {

FOS = new FileOutputStream (file);

Set the encoding set at output time

Xml.setoutput (FOS, "utf-8");

Setting the output document as a standalone XML

Xml.startdocument ("Utf-8", true);

Set Root start tag

Xml.starttag (NULL, "students");

Looping through the generation of student elements

for (int i=0;i<list_name.size (); i++)

{

Xml.starttag (NULL, "student");

Xml.starttag (NULL, "name");

Xml.text (List_name.get (i));

Xml.endtag (NULL, "name");

Xml.starttag (null, "sex");

Xml.text (List_sex.get (i));

Xml.endtag (null, "sex");

Xml.starttag (NULL, "age");

Xml.text (List_age.get (i));

Xml.endtag (NULL, "age");

Xml.starttag (NULL, "tel");

Xml.text (List_tel.get (i));

Xml.endtag (NULL, "tel");

Xml.endtag (NULL, "student");

}

Set Root end tag

Xml.endtag (NULL, "students");

Set document End

Xml.enddocument ();

Freeing resources

Fos.close ();

Toast.maketext (Mainactivity.this, "Save succeeded", "the"). Show ();

} catch (Exception e) {

Toast.maketext (Mainactivity.this, "Save Failed", +). Show ();

}

}

});


This article is from the "Android Development 0 Foundation" blog, please make sure to keep this source http://jinchao.blog.51cto.com/9651275/1586803

How Android generates XML file data

Related Article

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.