Hello ,
developing application with form having multiple fields, at the end
user need to submit the information.
On this event, all the data need to be stored in XML file.
thus XML write is required. plus when user asks for particular id then
the data filled by that id is also to be displayed thus XML read is
required.(search operation)
Following is the code I tried for generating sample xml.
/////////////////////////////////////////////////////////////////////////////////////////////
 FileOutputStream fileos = null;
                                try{
                                        
fileos=openFileOutput("newxml.xml",Context.MODE_PRIVATE);
                                        Log.v("info","fileoutput open");
                                //      fileos = new 
FileOutputStream(newxmlfile);
                                }catch(FileNotFoundException e){
                                        Log.e("FileNotFoundException", "can't 
create
FileOutputStream");
                                }
                                // create a XmlSerializer in order to write xml 
data
                                XmlSerializer serializer = Xml.newSerializer();
                                try {
                                        //we set the FileOutputStream as output 
for the
serializer, using UTF-8 encoding
                                                serializer.setOutput(fileos, 
"UTF-8");
                                                //Write <?xml declaration with 
encoding (if encoding not null)
and standalone flag (if standalone not null)
                                                serializer.startDocument(null, 
Boolean.valueOf(true));
                                                //set indentation option
                                                
//serializer.setFeature("http://xmlpull.org/v1/doc/
features.html#indent-output", true);
                                                //start a tag called "root"
                                                serializer.startTag(null, 
"root");
                                                //i indent code just to have a 
view similar to xml-tree
                                                        
serializer.startTag(null, "child1");
                                                        serializer.endTag(null, 
"child1");

                                                        
serializer.startTag(null, "child2");
                                                        //set an attribute 
called "attribute" with a "value" for
<child2>
                                                        
serializer.attribute(null, "attribute", "value");
                                                        serializer.endTag(null, 
"child2");

                                                        
serializer.startTag(null, "child3");
                                                        //write some text 
inside <child3>
                                                        serializer.text("some 
text inside child3");
                                                        serializer.endTag(null, 
"child3");

                                                serializer.endTag(null, "root");
                                                serializer.endDocument();
                                                //write xml data into the 
FileOutputStream
                                                serializer.flush();
                                                //finally we close the file 
stream
                                                fileos.close();

                                        //TextView tv = 
(TextView)this.findViewById(R.id.result);
                                                //tv.setText("file has been 
created on SD card");
                                                Log.v("info","file has been 
created on SD card");
                                                return true;
                                        } catch (Exception e) {
                                                Log.e("Exception","error 
occurred while creating xml file");
                                                return false;
                                        }
//////////////////////////////////////////////////////////////////////////////////////////////////////
executed this with actual device but,  no new xml file is created.
where to store this programatically created xml file?
On emulator if I want to test this application, where the xml file
will get stored?
Pls guide me whats going wrong?
Thanks.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to