public static void writeXmlBean(XMLBean xmlBean) throws IOException {

    if (null != xmlBean) {
      File file = new File(xmlBean.getPath());
      if (!file.exists()) {
        // file.mkdirs();
        file.getParentFile().mkdirs();
        file.createNewFile();
      }

      if (file.canWrite()) {

        StringBuilder sbd = new StringBuilder();
        // final String END_LINE = "\r\n";
        sbd.append("<?xml version=\"1.0\" encoding=\"");
        sbd.append(xmlBean.getCharset());
        sbd.append("\"?>").append(END_LINE);
        sbd.append("<?xml-stylesheet type=\"text/xsl\" href=\"style.xsl\"?>");
        sbd.append(END_LINE);
        sbd.append("<");
        sbd.append(xmlBean.getRootName());
        Class<?> beanClass = xmlBean.getBeanClass();
        String bcs = null == beanClass ? "" : beanClass.getName();
        sbd.append(" class=\"").append(bcs);
        sbd.append("\" >").append(END_LINE);
        // TODO classforname
        //        iXmlProcess = XMLProcessFactory.getXmlProcess(xmlBean.getRootName());
        List<?> itemList = xmlBean.getItemList();
        Set<Object> objSet = new HashSet<Object>();
        if (null != itemList && !itemList.isEmpty()) {
          objectToXmlString(itemList, sbd, objSet, null);
        } else {
          objectToXmlString(xmlBean.getBean(), sbd, objSet, null);
        }
        sbd.append("</").append(xmlBean.getRootName()).append(">");
        OutputStreamWriter fw = null;
        try {
          fw = new OutputStreamWriter(new FileOutputStream(file),
              Charset.forName(xmlBean.getCharset()));
          fw.write(sbd.toString());
          // fw.append(new
          // String(sbd.toString().getBytes("ISO-8859-1"),"GBK"));
          fw.flush();
        } finally {
          if (null != fw)
            fw.close();
        }
      }
    }

  }