我想从xml文档对象中获取一些数据。我的幻想XML文件就是这样;如何从org.jdom.Document中的xml对象获取数据?
<root>
<body>
<oids>
<oid> </oid>
<oid> </oid>
<oid> </oid>
<oid> </oid>
</oids>
</body>
</root>
要做到这一点,我正在写一个函数;
public Vector<String> getOIDs(Document document){
Vector<String> oids = new Vector<String>();
Element root = document.getRootElement();
Element body = root.getChild("body");
Element element = body.getChild("oids");
List rows = (List) element.getChildren("oid");
/*
List rows = root.getChildren("oids");
for (int i = 0; i < rows.size(); i++) {
}
*/
return oids;
}
当我从网上看,我undeerstood,我应该使用List类来获得信,但是当我尝试它,我总是错误。你能帮我解决问题吗?
谢谢大家。
什么错误?编译错误?运行时错误?发布它们。帮助我们帮助你。读这可能会有所帮助:http://www.javaworld.com/javaworld/jw-05-2000/jw-0518-jdom.html – duffymo