package ioXml; import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import javax.swing.text.StyledEditorKit.ItalicAction; import org.jdom.Attribute; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import org.jdom.input.*; public class IoXmlRead { static Map <String ,String> xmlMap=new HashMap<String, String>(); public static void main(String[] args) { preCrElement(); Set<String> hh=xmlMap.keySet(); Iterator<String> i=hh.iterator(); while(i.hasNext()){ String key = i.next(); String value = xmlMap.get(key); System.out.println(key+":"+value); } } public static void preCrElement(){ SAXBuilder builder = new SAXBuilder(); try { Document doc = builder.build(new File("E:/Users/Administrator/workspace/GFJ/src/art.xml")); Element root = doc.getRootElement(); createElement(root); } catch (JDOMException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public static void createElement(Element e){ Element pre = e.getChild("protest"); List<Element> list=e.getChildren(); if(list!=null && list.size()>0){ for(Element ele : list){ createElement(ele); } }else{ Element el=(Element) e.getParent(); Element jir = e; String name = e.getName(); String nodeText = jir.getText(); xmlMap.put(name,nodeText); } } }