如内存卡中已存在xml文件如下:
<A>
<b>b1</b>
<b>b2</b>
</A>怎么向文件中添加<b>b3</b>的数据???
<A>
<b>b1</b>
<b>b2</b>
</A>怎么向文件中添加<b>b3</b>的数据???
解决方案 »
- 求助ListView一个简单例子
- 新人,在listview中加载的spinner,spinner内容怎么保存?
- android 调用默认铃声后怎么改起始的默认选择位置?
- MediaPlayer只有声音没图象,在线等啊!!!
- JAVA的byte[]转到 native中的 unsigned char的问题
- mediaplayer的问题
- 自定义notification布局 怎么打jar包
- mapController = mapView.getController(); 不能用
- 怎么在软件上显示 手机的地理位置
- NDK 串口 基于intel芯片
- android开发中为了代码复用,多加一个文件,速度竟慢很多,这是为什么呢?
- mt6575:find: `mediatek/source/frameworks/oobewidget/java/android': No such file
import java.io.FileOutputStream;
import java.io.IOException;import org.jdom.Attribute;
import org.jdom.Comment;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;public class JDomOutput
{
public static void main(String[] args) throws IOException
{
//创建文档
Document document = new Document();
//创建根元素
Element people = new Element("people");
//把根元素加入到document中
document.addContent(people);
//创建注释
Comment rootComment = new Comment("将数据从程序输出到XML中!");
people.addContent(rootComment);
//创建父元素
Element person1 = new Element("person");
//把元素加入到根元素中
people.addContent(person1);
//设置person1元素属性
person1.setAttribute("id", "001");
Attribute person1_gender = new Attribute("gender", "male");
person1.setAttribute(person1_gender);
Element person1_name = new Element("name");
person1_name.setText("刘德华");
person1.addContent(person1_name);
Element person1_address = new Element("address");
person1_address.setText("香港");
person1.addContent(person1_address);
Element person2 = new Element("person");
people.addContent(person2);
person2.setAttribute("id", "002").setAttribute("gender","male");//添加属性,可以一次添加多个属性
Element person2_name = new Element("name");
person2_name.setText("林志颖");
person2.addContent(person2_name);
Element person2_address = new Element("address");
person2_address.setText("台湾");
person2.addContent(person2_address);
//设置xml输出格式
Format format = Format.getPrettyFormat();
format.setEncoding("utf-8");//设置编码
format.setIndent(" ");//设置缩进
//得到xml输出流
XMLOutputter out = new XMLOutputter(format);
//把数据输出到xml中
out.output(document, new FileOutputStream("jdom.xml"));//或者FileWriter
}}
当时是想问在Android里如何对xml进行动态修改的,当时一直用XmlSerializer试没有成功,就改用数据库了……