ff.xml
<?xml version="1.0" encoding="UTF-8"?>
<RECORDS>
<RECORD>
<NAME>XXX</NAME>
<E_MAIL>6364644915@qq.com</E_MAIL>
</RECORD>
<RECORD>
<NAME>BBBBB</NAME>
<E_MAIL>754545408010@qq.com</E_MAIL>
</RECORD>
</RECORDS>
ReadXml.java package org.email; import java.io.InputStream; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader; /** * @author linfenliang * */ public class ReadXml { // public List<String> GetRecipientAddress() { public Map<String, String> GetRecipientAddress() { // 调用dom4j读取xml文件配置信息,获取下载的路径。 SAXReader reader = new SAXReader(); Document doc = null; // List<String> listReceiver = new ArrayList<String>(); Map<String, String> friendinfo = new HashMap<String, String>(); try { InputStream in = getClass().getClassLoader().getResourceAsStream( "ff.xml"); doc = reader.read(in); } catch (DocumentException e1) { e1.printStackTrace(); } Element email = doc.getRootElement(); Element foo = null; for (Iterator iter = email.elementIterator("RECORD"); iter.hasNext();) { foo = (Element) iter.next(); friendinfo.put(foo.elementText("NAME").toString(), foo.elementText( "E_MAIL").toString()); } return friendinfo; } // test public static void main(String[] args) { ReadXml rx = new ReadXml(); Map<String, String> friendsInfo = new HashMap<String, String>(); friendsInfo = rx.GetRecipientAddress(); for (Map.Entry<String, String> me : friendsInfo.entrySet()) { System.out.println(me.getValue()); } } }