Hi Folks,

I am new to java programming. I have an xml file

<File>
<XMLFile>
 <Type = "TypesFirst">
  <myI>17</myInt>
  <myS>Type one</myS>
  <myD>3.14</myD>
  <myL>1212121</myL>
  <myC>D</myC>
 </Type>
</XMLFile>
<XMLFile> 
 <Type = "TypesSecond">
  <myI>17</myInt>
  <myS>Type two</myS>
  <myF>7.14</myF>
  <myL>121456</myL>
  <myC>D</myC>
 </Type>
</XMLFile>
</File>

So I have to deserialize this file in such a way that if the Type is "TypesFirst" it goes to Object1 otherwise it goes to "TypesSecond". So by the end of the parsing, I should have two objects viz. object 1 and object2 containing respective Types from XML file.

I have two classes Object1 and Object2 that contains respective datatypes.

How can it be done ?? Please HELP.

Recommended Answers

All 3 Replies

use SAX(Simple API for XML) parser jar or STAX(Simple streaming API for XML) parser jar to convert xml in to java objects

either will (or at least should) reject that XML as it is invalid :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.