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();
}