Element e = doc.getRootElement(); Stack<Element> stack = new Stack<Element>(); stack.push(e); while (!stack.isEmpty()) { Element node = stack.pop(); if (!node.isTextOnly() && node.hasContent()) { List<Element> l = node.elements(); for(Element ele : l){ stack.push(ele);//所有非文本的节点一下子“装” } } else{ System.out.println(node.getTextTrim()); } }原文链接:https://www.f2er.com/xml/294855.html