Meaningless Drivel is fun!*
The moose likes XML and Related Technologies and the fly likes XMLDecoder used for reading multiple Object from XML. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XMLDecoder used for reading multiple Object from XML." Watch "XMLDecoder used for reading multiple Object from XML." New topic
Author

XMLDecoder used for reading multiple Object from XML.

Jacob James
Greenhorn

Joined: Jun 07, 2004
Posts: 9
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

Joined: Jan 23, 2002
Posts: 11962
    
    5
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.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Note that the XML you posted is not wellformed:
Jacob James
Greenhorn

Joined: Jun 07, 2004
Posts: 9
my apologies.

If someone can assist me on the matter, that would be great. Thanks
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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

Joined: Aug 26, 2001
Posts: 7610
Moving this to the XML forum. Please continue this discussion there. Thank you


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XMLDecoder used for reading multiple Object from XML.