1/10/2021 how to write data to xml file and save that xml in android application - Stack Overflow
how to write data to xml file and save that xml in android application
Asked 9 years, 7 months ago Active 7 years, 5 months ago Viewed 11k times
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
2 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
1 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.
By using our site, you
android acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
xml
our Terms of Service.
https://stackoverflow.com/questions/6340338/how-to-write-data-to-xml-file-and-save-that-xml-in-android-application/6340576 1/2
1/10/2021 how to write data to xml file and save that xml in android application - Stack Overflow
edited Jul 20 '13 at 13:44 asked Jun 14 '11 at 7:24
Peter Lawrey prasad.gai
491k 70 685 1065 2,899 10 52 92
1 Answer Active Oldest Votes
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.
6
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.
answered Jun 14 '11 at 7:48
MatF
1,698 2 15 31
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service.
https://stackoverflow.com/questions/6340338/how-to-write-data-to-xml-file-and-save-that-xml-in-android-application/6340576 2/2