// 1.获取解析器 SAXReader sax =new SAXReader(); //2.获得docunment文档对象 Document doc =sax.read("src/demo03/schema.xml"); //3.获得根元素 Element root =doc.getRootElement(); //System.out.println(root.getName()); System.out.println(root.attributeValue("version")); //4.获取根元素下的子元素 List<Element> list =root.elements(); //5.遍历 for(Element e:list){ if("servlet".equals(e.getName())){ Element servletname =e.element("servlet-name"); Element servletclass =e.element("servlet-class"); System.out.println(servletname+" "+servletclass); System.out.println(servletclass.getText()); } }