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

Creating XML -- Need help

 
Kashyap Hosdurga
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21120
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you William.
You gave me exactly what I was looking for.

Thanks,
Kashyap
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic