Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert set of data into XML document

 
Anandh R
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a set of data(stored in hashtable) and I need to convert it into XML doc.
Any ideas about how to proceed
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you want to produce an external XML document (with <tags> etc.) or an in-memory object of class Document?
If it is the first, and the objects in your hashtable are strings (or things representable as strings, such as numbers) then you need something like:

if it is the second case, the you need something like:

I hope this helps.
 
Anandh R
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a hash like this

My XML doc is supposed to be
<Register>
<name></name>
<Address>
<ad1></ad1>
<city></city>
<contact>
<phone></phone>
<fax></fax>
</contact>
</Address>
</Register>
</Register>
How do I iterate in a Hashtable and find out if the key has a simple String value or Hashtable. If it has Hashtable I have to iterate further till I find a String
How do I do this
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about this slight modification of my first suggestion:

[This message has been edited by Frank Carver (edited December 01, 2000).]
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please note that The Java Ranch has a naming policy, described here and "Anandh R" is not a valid name. Please choose one which meets the requirements.
Thanks.
 
Anandh R
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx for the reply but there is some problem
creating hash table

displaying hash in XML way

I am to display
Register
Address
city vsssna city

contact
fax sss fax
phone sss phone
ad1 dddd ad1
name aaa name
Register
It is not closing my Address and Contact tags why??
More over why does "ad1" come as a separate element even though it is under Address
 
Anandh R
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx I got it..
 
Anandh R
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx for the help Frank ..
I need to know what are the imports i have to do if I am tying to save the hash into Document object.
How will I retieve a XML doc from this ???
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic