2

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

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

Robert Massaioli
  • 13,379
  • 7
  • 57
  • 73
RAAAAM
  • 3,378
  • 19
  • 59
  • 108

2 Answers2

4

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

Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103
  • @HariRam: What do you mean please check my code? Do you want us to do it for you? Just go use Simple XML, trust me, it is what you need and it will result in faster development times. – Robert Massaioli Jun 08 '11 at 13:24
0

The problem is Environment.getExternalStorageDirectory() is not available in android API for 2.1

You need to construct the directory address yourself. The method for which has already been given here: getExternalFilesDir alternative in android 2.1

Community
  • 1
  • 1
AndyRyan
  • 1,500
  • 12
  • 23