public void write(AddressBook book) throws AddressBookException {
        if (book != null) {
            logger.info("write addressBook to " + XMLFILENAME + "........");
            try {
                List<UserInfo> resultList = book.list();
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                DocumentBuilder db = factory.newDocumentBuilder();
                Document doc = db.newDocument();
                Element root = addElement(doc, doc, XMLROOTELEMENT_IDENTIFY, null);
                for (UserInfo user : resultList) {
                    Element userElement = addElement(doc, root, XMLELEMENT_IDENTIFY, null);
                    String userName = user.getName();
                    String address = user.getAddress();
                    String phoneNumber = user.getPhoneNum();
                    addElement(doc, userElement, NAME_IDENTIFY, userName);
                    addElement(doc, userElement, ADDR_IDENTIFY, address);
                    addElement(doc, userElement, PHONENO_IDENTIFY, phoneNumber);
                }

                File tmpFile = new File("temp.xml");
                if (tmpFile.exists()) {
                    tmpFile.delete();
                    logger.info("remove original temp.xml successfully");
                }
                TransformerFactory tFactory = TransformerFactory.newInstance();
                tFactory.setAttribute("indent-number", new Integer(2));
                Transformer transformer = tFactory.newTransformer();
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
                DOMSource source = new DOMSource(doc);
                StreamResult result = new StreamResult(tmpFile);
                transformer.transform(source, result);
                File xmlFile = new File(XMLFILENAME);
                if (xmlFile.exists()) {
                    xmlFile.delete();
                    logger.info("remove original " + XMLFILENAME + " successfully");
                }

                tmpFile.renameTo(xmlFile);
                logger.info("rename temp.xml to " + XMLFILENAME + "successfully");
                logger.info("finished writing xml file ");
            } catch (Exception e) {
                logger.error("write xml file error ", e);
                throw new AddressBookException("write xml file error", e);
            }
        } else {
            logger.info("addressbook not change,not needed to rewrite xml file ");
        }
    }