• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

convert XML to JAVA

 
PrashantKc Kumar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have following xml :

<servers>
<Env>
<AllEnvList>env1</AllEnvList>
<AllEnvList>env2</AllEnvList>
<AllEnvList>env3</AllEnvList>
</Env>
<AllEnvList name="env1">
<ListEnv>Dev</ListEnv>
<ListEnv>UAT</ListEnv>
<ListEnv>PROD</ListEnv>
</AllEnvList>
<AllEnvList name="env2">
<ListEnv>Dev</ListEnv>
<ListEnv>UAT1</ListEnv>
<ListEnv>UAT2</ListEnv>
<ListEnv>PROD</ListEnv>
</AllEnvList>
<AllEnvList name="env3">
<ListEnv>UAT</ListEnv>
<ListEnv>PROD</ListEnv>
</AllEnvList>
</servers>

I need to convert this xml into List<String> & last three in HashMap<String, List<String>> [ here Key String will the attribute name value ]. I tried some method but not able to get the value XXX from <ListEnv> XXX </ListEnv>
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apache Commons Digester can help with this if you only need the XML->Java direction. Or write a SAX parser that creates those objects.

If you need Java -> XML as well, JAXB might be the way to go.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic