Android Apps xml创建与解析PullXml
2011-12-05 14:26
302 查看
fos = context.openFileOutput(fileName, Context.MODE_PRIVATE); XmlSerializer serializer = Xml.newSerializer(); serializer.setOutput(fos,"UTF-8"); serializer.startDocument("UTF-8", true); serializer.startTag("", "root"); serializer.endTag("", "root"); serializer.endDocument(); serializer.flush(); fos.close();
PullXml
public static ResponseXML getResponseXML(Map<String,Object> params,Context context){ ResponseXML responseXML = new ResponseXML(); try { InputStream is = context.openFileInput("response.xml"); XmlPullParser parser = Xml.newPullParser(); parser.setInput(is, "utf-8"); int event = parser.getEventType(); String tag = null; while(event!=XmlPullParser.END_DOCUMENT){ if(event==XmlPullParser.START_TAG){ tag = parser.getName(); if("action".equals(tag)){ responseXML.setActionType(parser.getAttributeValue(null, "type")); } }else if(event == XmlPullParser.TEXT){ if("success".equals(tag)){ responseXML.setSuccess(parser.getText()); } }else if(event==XmlPullParser.END_TAG) tag = null; event = parser.next(); } is.close(); } catch (Exception e) { e.printStackTrace(); } return responseXML; }
相关文章推荐
- Android 创建与解析XML(四)—— Pull方式
- Android 创建与解析XML(三)---- PULL方式
- Android 创建与解析XML(四)—— Pull方式
- Android 创建与解析XML(四)—— Pull方式
- Android 创建与解析XML(四)—— Pull方式
- Android 创建与解析XML(四)—— Pull方式
- Android 创建与解析XML(四)――详解Pull方式
- Android 创建与解析XML(四)—— Pull方式
- Android 创建与解析XML(四)—— Pull方式
- Android 创建与解析XML(四)—— Pull方式
- Android 创建与解析XML(四)—— Pull方式
- Android 创建与解析XML(四)—— Pull方式
- Android 创建与解析XML(四)—— Pull方式
- android利用XmlPullParse对XML进行解析读取(1) + (2) 总结
- Android开发之使用PULL解析和生成XML
- android使用XmlPullParser来解析XML文件
- Android 解析XML 之pull
- Android--解析XML之PULL
- [android] 采用pull解析xml文件
- Android下Pull生成xml与解析xml