在Android中把内容写到XML文件中
在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文件中的更多相关文章
- Android中通过代码获取arrays.xml文件中的数据
android工程res/valuse文件夹下的arrays.xml文件中用于放各种数组数据,比如字符串数组.整型数组等,数组中的数据可能是具体的值,也有可能是对资源数据的引用,下面针对这两种情况通过 ...
- 将一个文件中的内容,在另一个文件中生成. for line in f1, \n f2.write(line)
将一个文件中的内容,在另一个文件中生成. 核心语句: for line in f1: f1中的所有一行 f2.write(line) ...
- vue项目中使用bpmn-流程图xml文件中节点属性转json结构
内容概述 本系列“vue项目中使用bpmn-xxxx”分为七篇,均为自己使用过程中用到的实例,手工原创,目前陆续更新中.主要包括vue项目中bpmn使用实例.应用技巧.基本知识点总结和需要注意事项,具 ...
- VBScript Sample:遍历文件夹并获取XML文件中指定内容
案例: 我有一个文件夹,里面有很多子文件夹,每个子文件夹中都存在一个相同名字的XML文件,XML文件里面的标签结构相同,只是内容不同,XML文件中包含ID,Name等标签. 文件夹及文件结构如下图: ...
- 将应用程序中的一些参数写到xml配置文件中
最近碰到一个问题,需要将程序中的一些基本参数写到xml文件中,虽然网上有好多现成的代码,但是觉得对xml不熟悉,果断就研究了一下.先说一下大体思路吧,我设计了一个用来读取和回填的类,然后定义了一个接口 ...
- arrays.xml文件中添加drawable数组的问题
一.问题描述 今天遇到一个需求,将java中的数组搬进arrays.xml文件中 R.drawable.menu_share_pic_item, R.drawable.menu_share_wecha ...
- Struts2 | struts.xml文件中使用method属性和通配符简化action标签和Action处理类的编写
转自:https://www.jianshu.com/p/310e89ee762d 在Struts2框架中,我们知道基本的Action标签只能实现一个url请求对应一个Action处理类.那么我们如果 ...
- Spring 在xml文件中配置Bean
Spring容器是一个大工厂,负责创建.管理所有的Bean. Spring容器支持2种格式的配置文件:xml文件.properties文件,最常用的是xml文件. Bean在xml文件中的配置 < ...
- 《!--suppress ALL --> 在Android XML 文件中的用途是什么?
<!--suppress ALL --> 在Android XML 文件中的用途是什么? 警告一次又一次地出现在谷歌地图的 XML 文件中,但是当我使用时,所有警告都被禁用.那么压制所有评 ...
随机推荐
- POJ3276(遍历+区间修改)
http://poj.org/problem?id=3276 题意:n(n<=5000)头牛站成线,有朝前有朝后的的,然后每次可以选择大小为k的区间里的牛全部转向,会有一个最小操作m次使得它们全 ...
- set 与 map 的第一次尝试
map 杭电6015http://acm.hdu.edu.cn/showproblem.php?pid=6015 基本用法:map<string,int>mp; mp[class[ i ...
- day7 python学习
今日内容# 枚举 此代码可以用于对有一定值的列表进行按带序列号的方式打印出来 lis=['手机','电脑','潜艇','手表'] for index,i in enumerate(lis,1): pr ...
- PHP独立环境搭建细节
一.安装前准备: 准备安装软件此处以以下软件为例: Appache:httpd-2.2.21-win32-x86-openssl-0.9.8r.msi MySQL: mysql-5.5.21-win ...
- jquery append、prepend、before等等
1.jQuery append() 方法 jQuery append() 方法在被选元素的结尾插入内容. 实例 复制代码代码如下: $("p").append("Some ...
- Promise 知识点
.done() Promise 对象的回调链,不管以then方法或catch方法结尾,要是最后一个方法抛出错误,都有可能无法捕捉到(因为 Promise 内部的错误不会冒泡到全局).因此,我们可以提供 ...
- yii2 rbac权限管理学习笔记
下面介绍一个 yii2 的 Rbac 权限管理设置,闲话少说,直接上代码, 1.首先我们要在组件里面配置一下 Rbac ,如下所示(common/config/main-local.php或者main ...
- HBase的BlockCache
BlockCache 首先要明白Block,在HBase里面存储的最小单元:在memstore向硬盘刷的时候,如果目标block的大小+size之后大于MAX_SIZE,将会新创建一个block来存储 ...
- MYSQL的空间查询(转帖)
SELECT x(location),y(location) FROM frddata.points; 本文将向各位介绍如何使用MySql5.x中的空间数据库,并展示一下它高效的性能(前提是正确使用) ...
- 转:使用JMeter创建数据库(Mysql)测试
我的环境:MySQL:mysql-essential-5.1.51-win32 jdbc驱动:我已经上传到csdn上一个:http://download.csdn.net/source/3451945 ...