Topic: 传值问题

  Print this page

1.传值问题 Copy to clipboard
Posted by: goldminer
Posted on: 2003-06-13 17:33

/**
* 读取XML文件所有信息
*/
public Vector LoadXML(String path)throws Exception{
Vector xmlVector = null;
FileInputStream fi = null;
try{
fi = new FileInputStream(path);
xmlVector = new Vector();
SAXBuilder sb = new SAXBuilder();
Document doc = sb.build(fi);
Element root = doc.getRootElement(); //得到根元素
List books = root.getChildren(); //得到根元素所有子元素的集合
Element book =null;
XmlBean xml =null;
for(int i=0;i<books.size();i++){
xml = new XmlBean();
book = (Element)books.get(i ); //得到第一本书元素
xml.setbookname(book.getChild("书名").getText());
xml.setauthor(book.getChild("作者").getText());
xmlVector.add(xml);
}
}
catch(Exception e){
System.err.println(e+"error");
}
finally{
try{
fi.close();
}
catch(Exception e){
e.printStackTrace();
}
}
System.out.println("ddd");
return xmlVector;
}

public static void main(String[] args) throws IOException {

try{
String k;
k=XmlBean.LoadXML("testC.xml");
out.printKiss;
}finally{
socket.close();
}
}

我想在 LoadXML()取得xml文件,然后输出书名和作者的值给k.或者把xml文件的内容传给k。怎样才能实现啊?

2.Re:传值问题 [Re: goldminer] Copy to clipboard
Posted by: archonLing
Posted on: 2003-06-15 22:22

There are 2 obvious errors in you code.

1. LoadXML method is not static, so you can't call XmlBean.LoadXML() directly.
2. Type mismatch. You are assign "String k = (Vector)XmlBean.LoadXML("testC.xml")

How did you get your code to compile?

3.Re:传值问题 [Re: goldminer] Copy to clipboard
Posted by: gus
Posted on: 2003-06-17 03:00

StringBuffer is better


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923