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 例外が発生します。