2

JDOm とトランスフォーマーの概念を使用して XML データを変更しようとしましたが、この 2 つの関数は 2.2 バージョンで動作します。しかし、2.1 でコンパイルしようとすると、例外が発生します。また、Google でこの問題を検索したところ、2.1 バージョンはトランスフォーマーの概念をサポートしていないことがわかりました。XML ファイルを変更する別の方法は何ですか。

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();
}

このコードは 2.2 バージョンで動作しますが、同時にこれを 2.1 でコンパイルすると、FleNotFound 例外が発生します。

4

2 に答える 2

4

シンプル XMLを使用して、オブジェクト内の xml ファイルを読み取り、その状態を変更して書き戻すことができます。

于 2011-06-08T12:23:07.477 に答える
0

問題はEnvironment.getExternalStorageDirectory()、Android API for 2.1 では利用できないことです。

ディレクトリ アドレスは自分で作成する必要があります。すでにここで与えられているメソッド: Android 2.1 の getExternalFilesDir 代替

于 2013-04-28T10:55:23.537 に答える