GeeCON Prague 2014*
The moose likes XML and Related Technologies and the fly likes Creating XML -- Need help 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 "Creating XML -- Need help" Watch "Creating XML -- Need help" New topic
Author

Creating XML -- Need help

Kashyap Hosdurga
Ranch Hand

Joined: Sep 19, 2005
Posts: 90
Hi All,

We are planning to do a project that involves following steps

1. We have a DTD, a CSV(comma separated value) file.
2. We need to create a XML file reading from the CSV file and it should adhere to DTD given.

My plan to do this is to create a tree using DOM from the DTD and read values from the CSV file and generate the XML file.

Please let me know I am missing anything here.
I am new to XML and related technologies so please forgive me if I have written anything dumb.

Thanks
Kashyap
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

I don't understand what this means:
to create a tree using DOM from the DTD
If it were up to me I would do this:

1. Create an empty DOM.
2. Read values from the CSV file and add elements etc. to the DOM.
3. Write the DOM to a file.
Kashyap Hosdurga
Ranch Hand

Joined: Sep 19, 2005
Posts: 90
Paul,
Thanks a lot for the reply.
Can you please correct me if I am wrong in understanding what you have explained.

If I have to create an empty DOM, I must read the DTD and create empty DOM. (Here empty means we have tags but no values associated to the tags).
Then read the values from the CSV file and write to another file.


Thanks,
Kashyap
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12791
    
    5
If I have to create an empty DOM, I must read the DTD and create empty DOM.


You are working with some realllly bad assumptions there. A DTD is NOT sufficient to create a DOM - take a look at the DTD for HTML for example. A DTD constrains the structure of a XML document but thats about all you can say.

How much have you done to relate the values in the CSV to the elements in the DOM? For each item in the DTD, do you know which is the corresponding CSV value?

It sounds like you want a DOM with a root element that contains repeating elements, one for each line. Each line element will contain all the CSV data from one line as elements or attributes according to the DTD.

Converting various text formats to XML is a common problem. You may be able to use one of the existing toolkits discussed in my article on XML pipelines. I would suggest looking at the ServingXML toolkit first.

Bill
Kashyap Hosdurga
Ranch Hand

Joined: Sep 19, 2005
Posts: 90
Thank you William.
You gave me exactly what I was looking for.

Thanks,
Kashyap
 
GeeCON Prague 2014
 
subject: Creating XML -- Need help