Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XMLDecoder used for reading multiple Object from XML.

 
Jacob James
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
my apologies.

If someone can assist me on the matter, that would be great. Thanks
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • 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.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the XML forum. Please continue this discussion there. Thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic