你可以使用jdom进行读取xml文件,然后使用jdbc建立表,不过你要生成类就不知道你要生成什么样子了呢。

解决方案 »

  1.   

    是不是就生成需要的set/get方法呢,如果是应该很简单的。
      

  2.   

    用jsp或servlet(java语言),2个100分,一旦可以马上结贴,决不失言!
      我是新手最好具体一点。
       谢谢!
      

  3.   

    大致的过程应该是:
    指定xml文件-〉使用jdom打开该xml文件-〉读取表名及各个字段的信息-〉组装成对应的sql语句-〉使用jdbc建立数据库连接-〉执行该sql语句-〉使用fileiostream建立.java文件-〉将需要的java代码写入该文件-〉end
      

  4.   

    你可以看看:books.xml --待处理的xml文件<?xml version="1.0" encoding="UTF-8"?>
    <catalog>
    <book id="bk101">
    <author>Gambardella, Matthew</author>
    <title>XML Developer's Guide</title>
    <publish_date>
      <year>2000</year>
      <month>10</month>
      <day>1</day>
    </publish_date>
    <description>An in-depth look at creating applications with XML.</description>
    </book>
    <book id="bk102">
    <author>Ralls, Kim</author>
    <title>Midnight Rain</title>
    <publish_date>
      <year>2000</year>
      <month>12</month>
      <day>16</day>
    </publish_date>
    <description>A former architect battles corporate zombies.</description>
    </book>
    <book id="bk103">
    <author>Corets, Eva</author>
    <title>Maeve Ascendant</title>
    <publish_date>
      <year>2000</year>
      <month>11</month>
      <day>17</day>
    </publish_date>
    <description>After the collapse of a nanotechnology society in England.</description>
    </book>
    </catalog>使用DOM解析 --BookParser.javaimport javax.xml.parsers.*;
    import org.w3c.dom.*;
    import java.io.*;/**
     *使用DOM提取XML内容的例子
     */
    class BookParser{
    public static void main(String[] args){
    try{
    //获取一个XML解析器
    DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
    DocumentBuilder builder=factory.newDocumentBuilder();
    //解析XML文件
    Document document=builder.parse(new File("books.xml"));
    //去掉XML文档中空白部分
    document.normalize();
    //获取根节点并打印根节点的名称
    Element root=document.getDocumentElement();
    System.out.println("根原始的名称:"+root.getTagName());
    //获取所有的"book"标记,它是一个NodeList对象
    NodeList books=root.getElementsByTagName("book");
    //遍历NodeList
    System.out.println("书本列表");
    for(int i=0;i<books.getLength();i++){
    //获取books中的每一个元素
    Element book=(Element)books.item(i);
    //获取每个"book"标记的"id"属性
    String book_id=book.getAttribute("id");//或book.getAttributeNode("id").getValue();
    System.out.println("序号:"+book_id);
    //获取"book"标记下的每个元素
    System.out.print("作者:");
    System.out.println(book.getElementsByTagName("author").item(0).getFirstChild().getNodeValue());
    System.out.print("标题:");
    System.out.println(book.getElementsByTagName("title").item(0).getFirstChild().getNodeValue());
    //获取"publish_date"元素
    Element publishDate=(Element)book.getElementsByTagName("publish_date").item(0);
    //获取"publish_date"元素下的每个子元素
    String year=publishDate.getElementsByTagName("year").item(0).getFirstChild().getNodeValue();
    String month=publishDate.getElementsByTagName("month").item(0).getFirstChild().getNodeValue();
    String day=publishDate.getElementsByTagName("day").item(0).getFirstChild().getNodeValue();
    System.out.println("出版日期:"+year+"年"+month+"月"+day+"日");
    System.out.print("描述:");
    System.out.println(book.getElementsByTagName("description").item(0).getFirstChild().getNodeValue());
    System.out.println("--------------------");
    }
    }
    catch(Exception e2){}
    }
    }
      

  5.   

    谢谢
       zxhong(红透半边天)、jcq(疯子弟)、 kreven(天地无用恨离别) 等!
       我刚接触到这部分知识,在大家的热心帮助下,我会学好的!
       再次,谢谢大家的帮助,特别是“zxhong(红透半边天)”!