writing data into xml file placed in assets folder in android app file system



Please have a look at the following source code, i am using this method to write data into a xml file placed in assets folder of android file system.



public void completeWritingProcess() throws ProfessionalPABaseException
{
try
{
TransformerFactory transformerFactory = TransformerFactory.newInstance();

Transformer transformer = transformerFactory.newTransformer();

transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "notes.dtd");

System.out.println("dtd read");

DOMSource source = new DOMSource(xmlDocument);

System.out.println("accessing file read="+xmlDocument.getChildNodes());

FileOutputStream output = applicationContext.openFileOutput("notes.xml", Context.MODE_APPEND);

StreamResult result = new StreamResult(output);

System.out.println("file read");

transformer.transform(source, result);
}
catch (Exception exception)
{
System.out.println(exception.getLocalizedMessage()+"stsck trace="+exception.getStackTrace());
}
}


notes.dtd and notes.xml file is placed in assets folder in application folder structure. Notes.dtd is defined as follows:-



<!DOCTYPE notes [
<!ELEMENT notes (note) #REQUIRED>
<!ELEMENT note (type,noteItem+)>
<!ELEMENT type (#PCDATA)>
<!ELEMENT noteItem (data,isAlarm,isImportant)>
<!ELEMENT data (#PCDATA)>
<!ELEMENT isAlarm (#PCDATA)>
<!ELEMENT isImportant (#PCDATA)>
]>


Notes.xml is blank and i expect it to get have data when the method completeWritingProcess completes execution. I am not getting any exception. But the notes.xml file placed in assets folder is blank.


Note:- I am using my phone moto g 2nd gen for testing this functionality(not the emulator). I have also tried searching for notes.xml in my phone file structure(as i am testing my app on my phone, it is possible that notes.xml is created on my phone) using file manager app but notes.xml is not created in my phone file structure.


Please guide me where to look for this file notes.xml and please also tell me if my source code is capable of writing data into xml file. Thanks in advance.


No comments:

Post a Comment