代码如下:
SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(new File("C:\\a.xml")); Element root = doc.getRootElement(); String rootName = root.getName(); //"person" List dataList = root.getChildren(); Iterator i = dataList.iterator(); while (i.hasNext()) { Element e = (Element) i.next(); String eKey = e.getName(); //"name","age","address" String eValue = e.getText(); //"wang","22","beijin" System.out.println("eKey==="+eKey+" ;eValue==="+eValue); }
原文链接:https://www.f2er.com/xml/294304.html