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 ,
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 ,
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]
谢谢.
dealwithdata是不应该含main()的(saxParser也不应该有main()),那么该在什么地方执行对xml文挡的分析呢?如果在dealwithdata的构造器中调用saxParser.parserXMLFile("SAXXML.xml"),
在proapp调用dealwithdata时,saxParser对象是不是已经被回收了?因为我没有取到任何数据。分析之后要保证对象不被回收。茫然...
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;
}
...;
}
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中并没有数据啊.
大虾们再帮忙分析一下好吗?这个问题很急.
先谢了.