如何重写或在Android 2.1版本修改XML [英] How to rewrite or modify XML in android 2.1 version

查看:154
本文介绍了如何重写或在Android 2.1版本修改XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图修改使用JDOM和变压器的概念XML数据,这两个功能在2.2版本的作品。但每当我试图编译2.1我收到异常。此外,我在谷歌搜索到这个问题,他们提到2.1版不会支持变压器的概念。什么是修改的XML文件的另一种方法。

I tried to modify XML data using JDOm and transformer concept, this two functions are works in 2.2 version. but whenever i tried to compile in 2.1 i am getting exception. Also i searched this issue in google, they mentioned 2.1 version never support transformer concept. what is the alternative way to modify XML file.

String filePath = Environment.getExternalStorageDirectory() + getDir;  
File file = new File(filePath);
if (file.exists()) {
    Document document = (Document) builder.build(file);

    Element root = document.getRootElement();
    Element EditableTag = root.getChild("firsttag");
    EditableTag.setText("changed String");

    /**
     * Print the modified xml document
     */
    String des = new XMLOutputter().outputString(document);
    System.out.println("String: " + des);

    /**
     * Modify the orginal document using FileWritter
     */
    FileWriter fileWriter = new FileWriter(file);
    fileWriter.write(des);
    fileWriter.close();
}

这code是在2.2版本的作品,同时我编这2.1我收到FleNotFound例外。

This code is works in 2.2 version, at the same time i compile this in 2.1 i am getting FleNotFound exception.

推荐答案

您可以使用<一个href="http://www.google.ru/url?sa=t&source=web&cd=2&ved=0CCQQFjAB&url=http://simple.sourceforge.net/&ei=o2nvTbPJHMKe-QaTsrmECA&usg=AFQjCNE40FfELo6ftmZBNkdIi9a-W5QIzQ&sig2=VFd2mp8YdqVBSD-pmEwsvw"相对=nofollow>简单的XML 读取XML文件中的对象,修改它的状态和写回。

You can use Simple XML to read the xml-file in the object, modify its state and write it back.

这篇关于如何重写或在Android 2.1版本修改XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆