aspose file tools*
The moose likes Servlets and the fly likes read in a xml file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "read in a xml file" Watch "read in a xml file" New topic
Author

read in a xml file

Michael.H.Sun
Ranch Hand

Joined: Jan 18, 2001
Posts: 39
Hi everyone,
I would like to have a Java servlet that reads an XML file, determines the format of the data, creates a table in SQL Server 7.0 to accept the file and loads the file into the SQL Server table.
Please tell me if this is feasible. If so, would give me some basic instructions on coding it?
Greatly appreciate your help.
Michael
Chris Stehno
Ranch Hand

Joined: Feb 26, 2001
Posts: 180
Yes, it is feasable.
Use an XML parser (I recomment Xerces www.apache.org) to parse your xml file. I prefer using SAX parsers over DOM, but that is mostly a personal preference. Put some data type cues in your xml so that you can quickly determine the data format (such as a data type tag or something).
Use your content handler or read your DOM tree to create your SQL table.
Java and XML is a really good book on the subject from Oreilly.
Good luck.


- Chris Stehno, SCPJ
Michael.H.Sun
Ranch Hand

Joined: Jan 18, 2001
Posts: 39
Chris,
Thank you for the instructions. I will try what you said. If I have more questions, I may paste them again.
Michael
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
Use Jdom is a lot easier. www.jdom.org
Michael.H.Sun
Ranch Hand

Joined: Jan 18, 2001
Posts: 39
Thank you, Roseanne. I will try JCOM.
Michael
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: read in a xml file