xml/customers.xml
<?xml version="1.0" encoding="utf-8"?> <customers xmlns:android="http://schemas.android.com/apk/res/android"> <customer name="小明" tel="110" emall="110@qq.com"/> <customer name="小红" tel="120" emall="120@qq.com"/> <customer name="小光" tel="130" emall="130@qq.com"/> </customers>
XmlResourceParser xmlResourceParser = getResources().getXml(R.xml.customers); StringBuffer stringBuffer = new StringBuffer(""); try { while (xmlResourceParser.getEventType() != XmlResourceParser.END_DOCUMENT) { if (xmlResourceParser.getEventType() == XmlResourceParser.START_TAG) { String tag = xmlResourceParser.getName(); if (tag.equals("customer")) { stringBuffer.append(xmlResourceParser.getAttributeValue(0)); stringBuffer.append(xmlResourceParser.getAttributeValue(1)); stringBuffer.append(xmlResourceParser.getAttributeValue(2)); stringBuffer.append("\n"); } } xmlResourceParser.next(); } } catch (Exception e){} editText.setText(stringBuffer.toString());