• 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

XMLDecoder used for reading multiple Object from XML.

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have an xml problem I was hoping someone can help me with...

<?xml version="1.0" encoding="UTF-8" ?>
- <java version="1.4.1_01" class="java.beans.XMLDecoder">
- <object class="java.util.Vector">
- <void method="add">
- <object class="java.util.Vector">
- <void method="add">
<string>INDEX_KEY</string>
</void>
</object>
</void>
- <void method="add">
- <object class="java.util.Vector">
- <void method="add">
<string>7</string>
</void>
</object>
</java>

^^^^^^^^^^^^^^^^^

this is the simple XML file I have created, now I am looking for some way to call the two objects defined so that I can use them in my program. The code I use to call it is:

XMLDecoder XD = new XMLDecoder (new FileInputStream (strLocation));
TestData = XD.readObject ();
XD.close ();

this throws an exception also for which I have written a code to catch.

Can anyone tell me how to add/alter the code to accomodate for the multiple objects. Objects maybe more than 2 that have been defined above.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello "J Js",

First of all, welcome to the 'ranch! We have a couple of rules here, one of which (the naming policy) you must've missed during registration because three consonants don't count as a valid display name... You can edit your publicly displayed name through My Profile.

Thanks.
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that the XML you posted is not wellformed:
 
Jacob James
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my apologies.

If someone can assist me on the matter, that would be great. Thanks
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just wrote a little test that passed with flying colors:

So at least it should work... If you would post the exact XML and the code you're trying to read multiple objects from an InputStream, maybe we could figure out where's the catch.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to the XML forum. Please continue this discussion there. Thank you
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic