how to get data from xml object in org.jdom.Document?
I am trying to get some datas from xml document object. My imaginery xml file is like that;
<root>
<body>
<oids>
<oid> </oid>
<oid> </oid>
<oid> </oid>
<oid> </oid>
</oids>
</body>
</root开发者_如何学JAVA>
And to do that I am writing a function for that ;
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;
}
As I read from the Internet , I undeerstood that I should use List class to get the s but when I try it, I always get errors. Can you please help me to get the s.
Thank you all.
I can't see what is wrong in the code. The only thing that looks fishy is the explicit conversion to List. Why is that?
I'm guessing that you have imported the wrong List implementation. Make sure you have imported java.util.List.
In your XML, <body> and <oids> are siblings, i.e. they have the same parent. Your code assumes that <oids> is a child of <body>. That should hopefully get you going again.
精彩评论