Hi I am trying to use this code to put my xml info into an array and I cant seem to get it to work right. Sorry I am new to XML and Java. ------------------------------------------
-------------------------------------------------------- [ April 13, 2007: Message edited by: Paul Clapham ]
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.
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.
Tony. I have experience with XML processing in JavaScript ... so this might just be a question rather than a solution. Shouldn't there be a loop somewhere that is used to transfer xml data one element at a time into an array? I wondered what the lists are getting ... note that getAttributes and getChildren are plural ... but then you say you're only getting the first one.
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.
Doe, a deer, a female deer. Ray, a pockeful of sun. Me, a name, I call my tiny ad ...
a bit of art, as a gift, that will fit in a stocking