You can use HashMap and ArrayList to deal with your problem!
I have deal with this probem,if you need ,i can find these code and send to you.
and i can't understand your means really ,

解决方案 »

  1.   

    To dlite82941(毛毛):
      public class saxParser implements ContentHandler {
        ......
       ArryaList dataname=new ArrayList();
       ArrayList dataid=new ArrayList();
        ......
        }
      public class dealwithdata implements JRDataSource{......}
      public interface JRDataSource{
          public boolean next();
          public Object getFieldValue();
        }
      public class proapp{......}
      SAXXML.xml
      1,saxParser主要做:处理SAXXML.xml文件,从其中得到元素内容,将取得的内容存于
        ArrayList中.
      2,dealwithdata类中的方法getFieldValue(),它要取得ArrayList中的值。
      3,proapp调用dealwithdata:
         有一段大致是这样:
          protected dealwithdata dealWD=null;
          ......
          public boolean next(){
              ...... 
           hasNext()=dealwithdata.next();
           if (hasNext()){
              ......
              objectValue=dealWD.getFieldValue();
            } 
           }               
       4,saxParser 是我自定义的。dealwithdata除必须实现JRDataSource外无要求。
         proapp是给定的,
        
      这个问题我怎么也搞不定。帮忙给点意见好吗?
      另外,麻烦你把这方面的例子代码发给我好吗?
      [email protected]
      谢谢.
      

  2.   

    只有对xml文件分析过之后才能取得数据的。所以如果saxParser和dealwithdata合为一个类的话,
    dealwithdata是不应该含main()的(saxParser也不应该有main()),那么该在什么地方执行对xml文挡的分析呢?如果在dealwithdata的构造器中调用saxParser.parserXMLFile("SAXXML.xml"),
    在proapp调用dealwithdata时,saxParser对象是不是已经被回收了?因为我没有取到任何数据。分析之后要保证对象不被回收。茫然...
      

  3.   

    如果saxParser和dealwithdata合为一个saxdealwithdata,那么saxdealwithdata的构件构造器中调用parserXMLFile(new saxdealwithdata)就造成循环,得到StackOverflowError.此路不通。大虾们给点意见啊,我的脑袋都大了:-(
      

  4.   

    我用SAX分析xml(类A)得到的结果放入ArrayList al.现在类B要用到A所分析得到的结果
    al怎么办?A执行完了ArrayList al就被垃圾回收机制回收了.(B对象b)b.al肯定是不行的。我该怎么办呢?
    在B的构造方法中添加一个参数(A a).
    例子:class B{
    private  ArryaList al;
      public B(A a){
        al = a.getal()
      }
    ...;}class A{
     private  ArryaList al;
     public  A(){
     } public ArryaList getal(){
       return al;
     }
     ...;
    }
      

  5.   

    在sun jdk的源代码中用了大量的用构造方法传递对象引用的地方
      

  6.   

    class B{
    private  ArryaList al;
      public B(A a){
        al = a.getal()
        executeMethod();// 处理数据放入al;
        
        for (int i=0;al.isEmpty()&&i<2;i++)
          {
              System.out.println(i);
          }
      }
    ...;}class A{
     private  ArryaList al;
     public  A(){
     } public ArryaList getal(){
       return al;
     }
     ...;
    }
      上面的for语句处是能输出0,1的,由此可见al中并没有数据啊.
      大虾们再帮忙分析一下好吗?这个问题很急.
      先谢了.
      

  7.   

    看不懂你问的是什么,如果是取得list结果,那应该是在A中写成函数,然后从函数返回取得的list比较好,用的时候就调用这个函数就可以了 。