SAXReader saxread = new SAXReader(); Document document = saxread.read(new File("src/day2/domx/car.xml")); List elementlist = document.getRootElement().elements(); List carList = new ArrayList(); //存对象信息 for(Element el:elementlist) Car car = new Car(); car.setBand(el.elementText("车牌号")); car.setPlace("产地"); car.setTime(el.element("车牌").attributeValue("出产时间")); car.setPrice(Integer.parseInt(el.elementText("单价"))); carList.add(car); System.out.println("按单价排序前:"); show(carList); //System.out.println("按单价排序后:"); //sortByPriceDesc(carList); private void sortByPriceDesc(List carList) { Collections.sort(carList); show(carList); private void show(List carList) { if(carList!=null && carList.size()>0){ for(Car car : carList){ System.out.print("车牌:"+car.getBand()+"\t"); System.out.print("产地:"+car.getPlace()+"\t"); System.out.print("单价:"+car.getPrice()+"\t"); System.out.println("出产时间:"+car.getTime());