以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DOM/SAX/XPath 』  (http://bbs.xml.org.cn/list.asp?boardid=11)
----  紧急求救!十万火急!!!如何在DTD限制下产生xml文件?  (http://bbs.xml.org.cn/dispbbs.asp?boardid=11&rootid=&id=13639)


--  作者:lernji
--  发布时间:1/15/2005 5:25:00 PM

--  紧急求救!十万火急!!!如何在DTD限制下产生xml文件?
我现在遇到这么一个问题,从数据库中读出数据,然后在一个已有的DTD文件的约束下将这些数据保存在一个XML文件中,请问各位大虾如何解决呢?十万火急!!!在线等!!!多谢了!,下面是我写的源代码,不知道为什么文中的DTD文件对结果不起作用,晕死了!
import java.sql.*;
import java.io.*;
import org.jdom.*;
import org.jdom.output.*;

public class JDOMBuildXMLDoc {
  public void BuildXMLDoc(OutputStream out) throws IOException, JDOMException {
    Element eeeRoot, eee1, eee2;
    Document Doc;
    DocType DocT;

    eeeRoot = new Element("employees_information");
    Doc = new Document(eeeRoot);

    DocT = new DocType("employees_information", "DTDTest.dtd");
    Doc.setDocType(DocT);

    try {
      conn connDbBean = new conn();
      ResultSet RS_result = connDbBean.executeQuery("select * from employ");
      String name = "";
      String emp_id = "";
      String age = "";
      String sex = "";
      String address = "";
      String email = "";
      String tel = "";
      Element eee3;
      while (RS_result.next()) {
        name = RS_result.getString("name");
        emp_id = RS_result.getString("emp_id");
        age = RS_result.getString("age");
        sex = RS_result.getString("sex");
        address = RS_result.getString("address");
        email = RS_result.getString("email");
        tel = RS_result.getString("tel");

        eeeRoot = Doc.getRootElement();
        eee3=new Element("employs_data");
        eeeRoot.addContent(eee3);

        eee1 = new Element("name");
        eee2 = eee1.setText(name);
        eee2 = eee1.addAttribute("emp_id", emp_id);
        eee1 = eee3.addContent(eee2);

        eee1 = new Element("age");
        eee2 = eee1.setText(age);
        eee1 = eee3.addContent(eee2);

        eee1 = new Element("sex");
        eee2 = eee1.setText(sex);
        eee1 = eee3.addContent(eee2);

        eee1 = new Element("address");
        eee2 = eee1.setText(address);
        eee1 = eee3.addContent(eee2);

        eee1 = new Element("tel");
        eee2 = eee1.setText(tel);
        eee1 = eee3.addContent(eee2);

        eee1 = new Element("email");
        eee2 = eee1.setText(email);
        eee1 = eee3.addContent(eee2);

        XMLOutputter XMLOut = new XMLOutputter();
        XMLOut.output(Doc, out);

        FileWriter writer = new FileWriter("myFile.xml");
        XMLOut.output(Doc, writer);
        writer.close();
      }
    }
      catch (SQLException ex) {
        System.err.println(ex.getMessage());
      }
    }

  public static void main(String[] args) {
    try {
      JDOMBuildXMLDoc JDOMBuildDocInstance = new JDOMBuildXMLDoc();

      System.out.println("========================================");
      System.out.println("Now we build an XML document .....");
      System.out.println("========================================");
      JDOMBuildDocInstance.BuildXMLDoc(System.out);
      System.out.println("========================================");
    }
    catch (Exception e) {
      System.out.println(e.getMessage());
    }
  }
}


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
2,402.344ms