在Android中把内容写到XML文件中

        saveXmlButton.setOnClickListener(new OnClickListener() {

            @Override
public void onClick(View arg0) {
List<StudentInfo> studentInfos = StudentInfo.initStudentInfos();
try {
FileOutputStream os = openFileOutput(fileName, MODE_PRIVATE);
//获取XmlSerializer对象
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
org.xmlpull.v1.XmlSerializer xmlSerializer = factory.newSerializer();
//设置输出流对象
xmlSerializer.setOutput(os, "utf-8"); /*
* startDocument(String encoding, Boolean standalone)encoding代表编码方式
* standalone 用来表示该文件是否呼叫其它外部的文件。
* 若值是 ”true” 表示没有呼叫外部规则文件,若值是 ”false” 则表示有呼叫外部规则文件。默认值是 “yes”。
*/
xmlSerializer.startDocument("utf-8", true);
xmlSerializer.startTag("myNameSpace", "Students"); for (StudentInfo studentInfo : studentInfos) {
xmlSerializer.startTag(null, "student");
xmlSerializer.attribute(null, "id", studentInfo.getId()+"");
xmlSerializer.startTag(null, "name");
xmlSerializer.text(studentInfo.getName());
xmlSerializer.endTag(null, "name"); xmlSerializer.startTag(null, "address");
xmlSerializer.text(studentInfo.getAddress());
xmlSerializer.endTag(null, "address"); xmlSerializer.startTag(null, "phone");
xmlSerializer.text(studentInfo.getPhone());
xmlSerializer.endTag(null, "phone"); xmlSerializer.endTag(null, "student");
}
xmlSerializer.endTag("myNameSpace", "Students");
xmlSerializer.endDocument();
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}
});

在Android中把内容写到XML文件中的更多相关文章

  1. Android中通过代码获取arrays.xml文件中的数据

    android工程res/valuse文件夹下的arrays.xml文件中用于放各种数组数据,比如字符串数组.整型数组等,数组中的数据可能是具体的值,也有可能是对资源数据的引用,下面针对这两种情况通过 ...

  2. 将一个文件中的内容,在另一个文件中生成. for line in f1, \n f2.write(line)

    将一个文件中的内容,在另一个文件中生成. 核心语句: for line in f1: f1中的所有一行 f2.write(line)                                  ...

  3. vue项目中使用bpmn-流程图xml文件中节点属性转json结构

    内容概述 本系列“vue项目中使用bpmn-xxxx”分为七篇,均为自己使用过程中用到的实例,手工原创,目前陆续更新中.主要包括vue项目中bpmn使用实例.应用技巧.基本知识点总结和需要注意事项,具 ...

  4. VBScript Sample:遍历文件夹并获取XML文件中指定内容

    案例: 我有一个文件夹,里面有很多子文件夹,每个子文件夹中都存在一个相同名字的XML文件,XML文件里面的标签结构相同,只是内容不同,XML文件中包含ID,Name等标签. 文件夹及文件结构如下图: ...

  5. 将应用程序中的一些参数写到xml配置文件中

    最近碰到一个问题,需要将程序中的一些基本参数写到xml文件中,虽然网上有好多现成的代码,但是觉得对xml不熟悉,果断就研究了一下.先说一下大体思路吧,我设计了一个用来读取和回填的类,然后定义了一个接口 ...

  6. arrays.xml文件中添加drawable数组的问题

    一.问题描述 今天遇到一个需求,将java中的数组搬进arrays.xml文件中 R.drawable.menu_share_pic_item, R.drawable.menu_share_wecha ...

  7. Struts2 | struts.xml文件中使用method属性和通配符简化action标签和Action处理类的编写

    转自:https://www.jianshu.com/p/310e89ee762d 在Struts2框架中,我们知道基本的Action标签只能实现一个url请求对应一个Action处理类.那么我们如果 ...

  8. Spring 在xml文件中配置Bean

    Spring容器是一个大工厂,负责创建.管理所有的Bean. Spring容器支持2种格式的配置文件:xml文件.properties文件,最常用的是xml文件. Bean在xml文件中的配置 < ...

  9. 《!--suppress ALL --> 在Android XML 文件中的用途是什么?

    <!--suppress ALL --> 在Android XML 文件中的用途是什么? 警告一次又一次地出现在谷歌地图的 XML 文件中,但是当我使用时,所有警告都被禁用.那么压制所有评 ...

随机推荐

  1. 《DSP using MATLAB》Problem 3.4

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  2. spring boot redis -> @Cacheable,@CacheEvict, @CachePut

    https://blog.csdn.net/eumenides_/article/details/78298088?locationNum=9&fps=1 https://www.cnblog ...

  3. MySQL删除超大表操作

    ======================================================================== 问题原因 通常情况下,会使用innodb_file_p ...

  4. FastAdmin composer json 版本说明

    来源于 FastAdmin 执行 composer update 后将 ThinkPHP 升级到了 V5.1. FastAdmin  是基于 ThinkPHP 5.0.x 开发的,而 ThinkPHP ...

  5. 3d之ui快速切换图像

    Requirement canon相机continuous mode(Burst mode) 抓图variation (230~320ms) 1. python + opencv 用cvWaitKey ...

  6. 【转】每天一个linux命令(28):tar命令

    原文网址:http://www.cnblogs.com/peida/archive/2012/11/30/2795656.html 通过SSH访问服务器,难免会要用到压缩,解压缩,打包,解包等,这时候 ...

  7. Oracle DataBase单实例使用ASM案例(1)--ASM基本概念

    版权声明:本文为博主原创文章,未经博主允许不得转载. Oracle DataBase单实例使用ASM案例(1)--ASM基本概念 系统环境: 操作系统:RH EL5-64 Oracle 软件: Ora ...

  8. Java Web Service 学习笔记

    一.服务端 1. 创建Java工程 2. 创建接口HostipalServiceInterface package ws_server; import javax.jws.WebMethod; imp ...

  9. dubbo实战

    http://blog.csdn.net/hejingyuan6/article/details/47403299

  10. 【jmeter】jmeter之-断言和检查点

    断言就类似LoadRunner中的检查点.对上一个请求返回的信息,做字符串.数据包大小.HTML.XML.图片等做判断,确保返回的信息的准确性. 简单的来理解一下,上一章讲到,我们对用户名和密码进行了 ...