• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Read XML into Java Array

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
tony deprato
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry --here is the xml doc






 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I cant seem to get it to work right.



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?
 
tony deprato
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

CN
 
Ranch Hand
Posts: 409
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic