使用JDOM的,参考下。  public void XMLBuilder(NewsVO vo) throws SystemException
  {
    String posttime = com.chuhu.util.DateCommon.formatTime(vo.getPostDate());
    Document document = new Document(new Element("content"));
    Element title = new Element("title");
    document.getRootElement().addContent(title);
    title.addContent(TextCommon.gb2Uni(vo.getTitle()));    Element contentID = new Element("contentID");
    document.getRootElement().addContent(contentID);
    contentID.addContent(vo.getContentID().toString());    Element content = new Element("content");
    document.getRootElement().addContent(content);
    CDATA data = new CDATA(TextCommon.gb2Uni(vo.getContent()));
    content.addContent(data);    ProcessingInstruction pi = new ProcessingInstruction("xml-stylesheet","type=\"text/xsl\" href=\"/template/detail"+vo.getCategoryID().toString()+".xsl\"");
    document.addContent(0,pi);    //设定xml输出的格式
    XMLOutputter outp = new XMLOutputter();
    Format format = outp.getFormat();
    format.setEncoding("gb2312");
    format.setIndent("  ");
    outp.setFormat(format);
    try
    {
      //输出xml
      java.io.FileWriter writer = new java.io.FileWriter(vo.getXmlFilePath());
      outp.output(document,writer);
      writer.close();
    }
    catch(IOException ex)
    {
      throw new SystemException("创建XML文件失败");
    }
  }