标签:
package Dom4j; import org.dom4j.Document; import org.dom4j.Element; public class BookDaoDom4j { public boolean addBook(Book book){ boolean result=false; try { //1,得到Document对象 Document document=Dom4jUtil.getDocument(); Element root=document.getRootElement(); //2,利用DocumentHelper创建书 Element bookE=root.addElement("书"); //3,创建子元素 bookE.addElement("name").setText(book.getName()); bookE.addElement("author").setText(book.getAuthor()); bookE.addElement("price").setText(book.getPrice()); //4,更新文档 Dom4jUtil.writeXML(document); result=true; } catch (Exception e) { throw new RuntimeException(e); } return result; } public boolean removeBook(String name){ boolean result=false; return result; } }
标签:
原文地址:http://www.cnblogs.com/lzzhuany/p/4687812.html