假设我们的xml文件如下
192.168.1.108 5222 qq.com
那么我们读取的代码如下:
private void readConfig() throws Exception { Resources res = this.getResources(); XmlResourceParser parser = res.getXml(R.xml.config); int type = parser.getEventType(); while(type != parser.END_DOCUMENT){ if(type == parser.START_TAG){ String name = parser.getName(); if("chatServerIp".equals(name)){ chatServerIp = parser.nextText(); } else if("port".equals(name)){ port = Integer.parseInt(parser.nextText()); }else if("serviceName".equals(name)){ serviceName = parser.nextText(); } } type = parser.next(); } }