Meaningless Drivel is fun!*
The moose likes XML and Related Technologies and the fly likes Convert set of data into XML document 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 "Convert set of data into XML document" Watch "Convert set of data into XML document" New topic
Author

Convert set of data into XML document

Anandh R
Greenhorn

Joined: Nov 30, 2000
Posts: 5
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

Joined: Jan 07, 1999
Posts: 6920
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.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Anandh R
Greenhorn

Joined: Nov 30, 2000
Posts: 5
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

Joined: Jan 07, 1999
Posts: 6920
How about this slight modification of my first suggestion:

[This message has been edited by Frank Carver (edited December 01, 2000).]
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
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

Joined: Nov 30, 2000
Posts: 5
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

Joined: Nov 30, 2000
Posts: 5
Thanx I got it..
Anandh R
Greenhorn

Joined: Nov 30, 2000
Posts: 5
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 ???
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Convert set of data into XML document