Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML file into database?

Status
Not open for further replies.

cjtaylor

Programmer
Aug 12, 2001
69
US
Hello,

I need some help trying to store and XML file into a database without using stored procs. I tried doing it the same way you would an image, but to no avail. Does anyone have a code snippet of reading and writing a file to a database?

Thank you,
Chris Taylor
 
Could you be more specific?

Are you trying to store the data as is into a single row in a database? Are you trying to create several rows that represent the XML?

bassguy
 
Hi,

Thanks for your quick response, what I am trying to do is store a xml file as is into a field of a row in my database, So I can retrieve and reconstruct the xml file at a later time.

Thank you,
Chris Taylor
 
Just make the Field a Text field and Save the XML as is into it XML is Text Based Just pretend it is a really long answer to a question and insert it via the SQL insert string.


declare myxml as string

insert into mytable myXML



However, that said, I think that there are a lot better ways of storing the data than raw XML into a field.

hope that helps

bassguy
 
Thanks,

I was beginning to wonder if I could store it that way, I guess it's better to keep thing as simple as possible. You said in your last post

>>I think that there are a lot better ways of storing the >>data than raw XML into a field.

What would be a better way of doing this? The reason why I did it this way is because I needed to interface to a Borland C++ program that can read xml files but not Microsoft datasets.

Thanks again,
Chris
 
Well,

There are a lot of things you can do.

For starters, A dataset is XML it is just in a format that your other app cannot read.


Now I am a bit unclear but it sounds like you want a SQL database that can be the Back End end for 2 different application written with 2 different languages. To answer this you have decided to use XML with your SQL Server.

SO Far So good

If You Are using MS SQL Server,
I think you might want to check into the "For XML" Clause on a select statement.

in a nutshell it will take the data from you select statement and turn it into XML and stream out the XML into a virtual XML document.

With Dotnet you just use a XML reader to use the data

for the Borland app I assume there is also some sort of stream that you can read from.

check you SQL Server BOL for the FOR XML Clause there are a few options you can use after that to select the type XML that is streamed

Bassguy











 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top