This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
Tony, I reformatted your code by putting the code tags around it and fixing up the indentation to make it consistent. Easier on the eyes that way. Now, you say it doesn't work right. Can you tell us what it is supposed to do? All we see there is the code, so all we can tell is what it actually does. And it would help if you posted the input XML document too.
As Paul said, that is not a very useful problem description. What exactly should the code do, and how does its behavior deviate from that?
Joined: Mar 17, 2007
Sorry, I thought I stated it above. This java code should read xml elements into an array. I can only get the first element in the first position of the array. I ran my xml through a validator and it seems fine. I have used xml with php before but not Java.
Should there be some kind of x.item(i) i=0,1,2... kind of thing? x being the result of a get. [ April 14, 2007: Message edited by: Roger F. Gay ]
I don't think your code is doing anything much. And I'm not even sure it will run correctly if you run it. For example this:gets you a list of seven "uni" elements. (At least I think it does, I'm not really familiar with JDOM but that seems like the most reasonable thing for it to do.) But then you do this:And that, I think, should throw a ClassCastException. I wouldn't expect to be able to cast a List to an Element.
So, you might want to have a look at some JDOM tutorials. (The easiest way to find them is to stick "jdom tutorial" into your favourite Internet search engine and look at what comes back, but beware of old tutorials because JDOM went through a number of changes before version 1.0 was finalized.) Here is one that isn't too old, for example.
If you just want to put those seven "uni" elements into an array, then you have them in a List already so it's easy to get an array from that List. But I suspect your requirements will go beyond that once you get used to working with XML. So take some code from the tutorials and fiddle around with it.