给你个例子这是我用JDOM读xml文件
package Testbean;
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;
import java.util.List;
import java.util.Iterator;
import java.io.*;
public class read{  int recordcount=0;
  int columncount=0;
  SAXBuilder sb;
  Document doc;
  Element root,one;
  List all,record;
  
  //¼ÆËã³öXMLÎļþ½áµãµÄÊýÁ¿
  public int recordcount(String path)throws Exception{
sb = new SAXBuilder(); 
doc = sb.build(new FileInputStream(path)); 
root = doc.getRootElement();
all = root.getChildren();
recordcount=all.size();
return recordcount;
  }
  //¼ÆËã³öXMLÎļþ½áµãµÄÊýÁ¿
  public int columncount()throws Exception{
Iterator i = all.iterator();
        one = (Element) i.next();
        record = one.getChildren();
        columncount=record.size(); 
        return columncount;
  }
  //´ÓXMLÎļþ¶ÁÈ¡×Ö¶ÎÃû
  public String[] columnname()throws Exception{
   String []name;
   name=new String[columncount];
   int j=0;
Iterator i = record.iterator();

while (j<columncount) {
    one = (Element) i.next();
            name[j]= one.getName();
            j++;
        }
 
return name;
  }}

解决方案 »

  1.   

    自定义的tablib中,不能再使用struts的tablib,如何解决。
      

  2.   

    SAXBuilder saxBuilder = new SAXBuilder();
    Document jdomDocument = null;
    try{
    jdomDocument = saxBuilder.build(new File( "yourXMLFileName"));
    Element m_root=jdomDocument.getRootElement() ;
    if (m_root!=null)      {
    //获取节点
    Element tempEle= m_root.getChild("name");
    String tableName=tempEle.getText();
    List cols=tempEle.getChild("cols").getChildren("col");
    for(int i=0;i,cols.size();i++) {
    Element temp_Father=cols.get(i);
    //得到name
    Element temp_Child=temp_Father.getChild("name");
    String name=temp_Child.getText();
    //得到type
    temp_Child=temp_Father.getChild("type");
    String type=temp_Child.getText();
    //得到descript
    temp_Child=temp_Father.getChild("descript");
    String descript=temp_Child.getText();                                     ...
    变量保存
    ... }
    }
    }catch(Exception e) {
    System.out.println(e.toString());
    }

    连库
    建表