开发者

How to read xml values from specified path as shown in code

开发者 https://www.devze.com 2023-03-11 16:32 出处:网络
I created xml file getFilesDir().getAbsolutePath()+ File.separator + \"test.xml\" in this path, i want to read xml values from this path how can i do it. please send me code for accessing file on t

I created xml file

getFilesDir().getAbsolutePath()+ File.separator + "test.xml"

in this path, i want to read xml values from this path how can i do it. please send me code for accessing file on that path. this xml is created in this path in DDMS (data/data/<packagename>/files/xmlname.xml) please help me.

Thank You,

TextView  txtoldpwd=(TextView)findViewById(R.id.txtOldPwd);
TextView txtnewpwd=(TextView)findViewById(R.id.TxtNewPwd);
File objFile=new File(getFilesDir().getAbsolutePath()+ File.separator + "test.xml");
try {
    if (objFile.exists()){
        objFile.delete();
    }
    objFile.createNewFile();
    FileOutputStream  objFileStream=new FileOutputStream(objFile);

    XmlSerializer objXmlSrl=Xml.newSerializer();
    objXmlSrl.setOutput(objFileStream,"UTF-8");
    objXmlSr开发者_开发技巧l.startDocument(null, true);
    objXmlSrl.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    objXmlSrl.startTag(null, "ChangePassword");
    objXmlSrl.startTag(null, "Oldpassword");
    objXmlSrl.text(txtoldpwd.getText().toString());
    objXmlSrl.endTag(null, "Oldpassword");
    objXmlSrl.startTag(null, "Newpassword");
    objXmlSrl.text(txtnewpwd.getText().toString());
    objXmlSrl.endTag(null, "Newpassword");
    objXmlSrl.endTag(null, "ChangePassword"); 
    objXmlSrl.endDocument();
    objFileStream.close();
} catch (Exception e) {
    // TODO: handle exception
}


you can use ... XmlPullParser .. to parse xml file in android.

http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html

Doc about xml pull parser on android developer site. and little article with code snippest is given here ...

http://indiheaven.blogspot.com/2011/03/xml-parsing-in-android-using.html

0

精彩评论

暂无评论...
验证码 换一张
取 消