SAXReader saxReader = new SAXReader();
Document read = saxReader.read("src/books.xml");
Element rootElement = read.getRootElement();
System.out.println(rootElement);
Element book = rootElement.element("book");//如果你的对象只有一个的话,那么就是用element方法,否则就使用elements的方法
System.out.println(book.asXML());//asXML()方法就是把标签对象转换为字符串
Element nameElement = book.element("name");
String nameText = nameElement.getText();
System.out.println(nameText);
//直接获取标签名的文本内容
String name = book.elementText("name");
System.out.println(name);
String price = book.elementText("price");
System.out.println(price);
String author = book.elementText("author");
System.out.println(author);
Attribute sn = book.attribute("sn");
System.out.println(sn);
System.out.println(new Book(sn,name,Double.parseDouble(price),author));
07-18
5021
03-28
1862