刚才简单的看了下JDOM的文档,好像不支持schema校验,不过对xsl倒是支持的不错!
gz

解决方案 »

  1.   

    import org.jdom.*;
    import org.jdom.input.*;
    import org.jdom.output.*;
    import java.io.*;public class TestXml {
      public TestXml() {
      }  public void save(){
        try {
          Element element = new Element("all-item");
          Comment comment = new Comment("asdAsdasdasd");
          Document doc = new Document(null);
          ProcessingInstruction pi = new ProcessingInstruction
          ("xml-stylesheet", "href=\"bookList.html.xsl\" type=\"text/xsl\"");
          doc.addContent(pi);
          doc.setRootElement(element);
          Element childItem = new Element("item");
          Element itemChildTopic = new Element("topic");
          Element itemChildContent = new Element("content");
          childItem.addContent(itemChildTopic);
          childItem.addContent(itemChildContent);
          element.addContent(childItem);
          OutputStream out = new FileOutputStream("d:/asdfgh.xml");
          XMLOutputter outp = new XMLOutputter("", true, "GBK");
          outp.output(doc, out);
          out.close();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
      public static void main(String[] args) {
        TestXml testXml = new TestXml();
        testXml.save();
      }}
    web.xml里面的这句话 是用来验证文档的   具体什么意思自己查查看吧
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">