pull方式读xml
发布时间:2020-12-16 06:41:13 所属栏目:百科 来源:网络整理
导读:url.xml pre name="code" class="html"?xml version="1.0" encoding="utf-8"?urlfile urlhttp://192.168.1.2/wh/UploadData/url/urlfile pre name="code" class="java"public class getXmlValue {public static String getUrl(InputStream inputStream){ Str
url.xml <pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?> <urlfile> <url>http://192.168.1.2/wh/UploadData</url> </urlfile> <pre name="code" class="java">public class getXmlValue { public static String getUrl(InputStream inputStream){ String urltext=null; XmlPullParser xmlParser = Xml.newPullParser(); try { xmlParser.setInput(inputStream,"utf-8"); int evtType=xmlParser.getEventType(); while(evtType!=XmlPullParser.END_DOCUMENT){ switch(evtType){ case XmlPullParser.START_TAG: String tag = xmlParser.getName(); //如果是river标签开始,则说明需要实例化对象了 if ("url".equals(tag)) { urltext=xmlParser.nextText(); } break; default:break; } evtType=xmlParser.next(); } } catch (XmlPullParserException e) { // TODO Auto-generated catch block e.printStackTrace(); }catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } return urltext; } } <pre name="code" class="java"> public static void save(String URL,OutputStream out) throws Exception{ XmlSerializer serializer= Xml.newSerializer(); serializer.setOutput(out,"UTF-8"); serializer.startDocument("UTF-8",true); serializer.startTag(null,"urlfile"); serializer.startTag(null,"url"); serializer.text(URL); serializer.endTag(null,"url"); serializer.endTag(null,"urlfile"); serializer.endDocument(); out.flush(); out.close(); } InputStream inputStream= this.getClass().getClassLoader().getResourceAsStream("url.xml"); processURL=getXmlValue.getUrl(inputStream); if(processURL.length()==0){ <span style="white-space:pre"> </span>Toast.makeText(this,"url.xml文件有误",Toast.LENGTH_LONG).show(); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |