public class Dom4jSample { static final String xmlString = "<persons><person age=\"32\"><name>张三</name></person>" + "<person age=\"26\"><name>李四</name></person></persons>"; public static void main(String[] args) { try { Document doc = DocumentHelper.parseText(xmlString); List<Element> personList = doc.selectNodes("//persons/person"); for (Element person : personList) { System.out.println("姓名:" + person.elementText("name") + ";年龄:" + person.attributeValue("age")); } } catch (DocumentException e) { e.printStackTrace(); } } }