2

i am new developer in android application.i would like to write the data into xml file.i mean i would like to change the content like elements,tags,data in xml file.i can able to read an xml file in that file, i would like to change or modify and save that xml file.

i have written sample application to read xml as follows

FileInputStream fstream = new FileInputStream("/sdcard/book.xml");
  BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
  String strLine;
  //Read File Line By Line
  while ((strLine = br.readLine()) != null)   {
  // Print the content on the console
  System.out.println ("Xml file content====>"+strLine);


  data1.append(strLine);
  data1.append('\n');


  System.out.println("--------->"+data1.append(strLine)+"\n");

i have written this code in a method here book.xml is my xml file to change

when i call this method then i am getting out put with tags in logcat as follows

06-14 12:48:32.309: VERBOSE/(433): #######>>>>><?xml version="1.0" encoding="utf-8"?>
06-14 12:48:32.309: VERBOSE/(433): <Employee-Detail>
06-14 12:48:32.309: VERBOSE/(433): <Employee>
06-14 12:48:32.309: VERBOSE/(433): <Emp_Id>E-001</Emp_Id>
06-14 12:48:32.309: VERBOSE/(433): <Emp_Name>Vinod</Emp_Name>
06-14 12:48:32.309: VERBOSE/(433): <Emp_E-mail>[email protected]</Emp_E-mail>
06-14 12:48:32.309: VERBOSE/(433): </Employee>
06-14 12:48:32.309: VERBOSE/(433): <Employee>
06-14 12:48:32.309: VERBOSE/(433): <Emp_Id>E-002</Emp_Id>
06-14 12:48:32.309: VERBOSE/(433): <Emp_Name>Amit</Emp_Name>
06-14 12:48:32.309: VERBOSE/(433): <Emp_E-mail>[email protected]</Emp_E-mail>
06-14 12:48:32.309: VERBOSE/(433): </Employee>
06-14 12:48:32.309: VERBOSE/(433): <Employee>
06-14 12:48:32.309: VERBOSE/(433): <Emp_Id>E-003</Emp_Id>
06-14 12:48:32.309: VERBOSE/(433): <Emp_Name>Deepak</Emp_Name>
06-14 12:48:32.309: VERBOSE/(433): <Emp_E-mail>[email protected]</Emp_E-mail>
06-14 12:48:32.309: VERBOSE/(433): </Employee>
06-14 12:48:32.309: VERBOSE/(433): </Employee-Detail>

how can write or edit or modify the above xml as prophetically?

please any body can help

thanks in advance.

1 Answer 1

6

You could write a parser for your xml (use SAX for example) and store it into a object of a class which represents the fields and values of you xml.

Then edit the needed settings in the object and use a xml builder to make a xml file with the new values.

Then just write the file back to the device. See http://developer.android.com/guide/topics/data/data-storage.html for details on storing files.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.