pull解析xml文件代码如下:

public void PullParseXML(String filepath) {String res = "本结果是通过XmlPullParse解析:" + "/n";try {XmlPullParserFactory factory = XmlPullParserFactory.newInstance();XmlPullParser xmlPullParser = factory.newPullParser();File file = new File(filepath);if(!file.exists()){CreateXML();file = new File(filepath);}FileInputStream input=null;try {input = new FileInputStream(file);} catch (FileNotFoundException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}if(input == null)return;xmlPullParser.setInput(input,"UTF-8");int eventType = xmlPullParser.getEventType();String str="";try {while (eventType != XmlPullParser.END_DOCUMENT) {String nodeName = xmlPullParser.getName();switch (eventType) {case XmlPullParser.START_TAG:if ("XX1".equals(nodeName)) {str = xmlPullParser.nextText();res += "XX1 = "+str+"--";} else if ("XX2".equals(nodeName)) {str = xmlPullParser.nextText();res += "XX2 = "+str+"--";}else if ("XX3".equals(nodeName)) {str = xmlPullParser.nextText();res += "XX3 = "+str+"--";}else if ("XX4".equals(nodeName)) {str=xmlPullParser.nextText();res += "XX4 = "+str+"--";}else if ("XX5".equals(nodeName)) {str = xmlPullParser.nextText();res += "XX5 = "+str+"--";}break;default:break;}eventType = xmlPullParser.next();}} catch (IOException e) {e.printStackTrace();return;}} catch (XmlPullParserException e) {e.printStackTrace();return;}Log.e("PullParseXML:",res);}

2.写xml文件如下:

public void WriteXml(String filepath) throws IllegalArgumentException, IllegalStateException, IOException {File file = new File(filepath);if(!file.exists()){CreateXML();file = new File(filepath);}FileOutputStream out = null;try {out = new FileOutputStream(file);} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}if(out == null)return;        XmlSerializer serializer = Xml.newSerializer();        serializer.setOutput(out, "UTF-8");        serializer.startDocument("UTF-8", true);                serializer.startTag("", "SettingInfo");        String str = "0";//在此先随便写个数据serializer.startTag("", "XX1");serializer.text(str);serializer.endTag("", "XX1");serializer.startTag("", "XX2");serializer.text(str);serializer.endTag("", "XX2");str = "0";serializer.startTag("", "XX3");serializer.text(str);serializer.endTag("", "XX3");serializer.startTag("", "XX4");serializer.text(str);serializer.endTag("", "XX4");serializer.startTag("", "XX5");serializer.text(str);serializer.endTag("", "XX5");serializer.endTag("", "SettingInfo");        serializer.endDocument();        out.flush();        out.close();    }



---应该有获取xml的tag直接进行数据修改,会的童鞋还请在告知下,谢谢!


更多相关文章

  1. android 将bitmap缓存到本地
  2. android创建自定义对话框
  3. 2011.10.10(2)——— android Clipping关于剪切
  4. Android文件操作
  5. Android改变系统自带ProgressDialog的文字大小
  6. android 判断文件是否存在
  7. Android自学笔记之短信发送器
  8. Android(安卓)使用decodeFile方法加载手机磁盘中的图片文件
  9. NPM 和webpack 的基础使用

随机推荐

  1. Android(安卓)获取、移除 View 的 OnClic
  2. Android中使用SerialPort读取红外温度传
  3. Gradle、 Gradle Android(安卓)Plugin 、
  4. Android(安卓)studio gradle系列二.
  5. ubuntu11.0.4下编译Android
  6. Android(安卓)SystemUI之启动流程(一)
  7. Webview缓存处理
  8. 2013.07.12——— android red5安装
  9. Android(安卓)基础-1.0 按钮4种点击事件
  10. android模拟器不能上网