By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,818 Members | 1,381 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,818 IT Pros & Developers. It's quick & easy.

How to write a string from a database into a xml file?

P: 61
Hai,

i'm having a string in a specific field of a database...

now i want to retrive that string from the database
and i have to write that string into a xml file....

retriving is not a problem for me...

but how can i write that string to a xml file....

ie i have to write that string to a file which is to be saved as
xml file...

is there any writeFile method available for doing this
process..

Or is there any source codes available in the net?

I'm a beginner to C++....

Can any one plzz explain me....

thanks..
senthil
Dec 28 '06 #1
Share this Question
Share on Google+
8 Replies


10K+
P: 13,264
Hai,

i'm having a string in a specific field of a database...

now i want to retrive that string from the database
and i have to write that string into a xml file....

retriving is not a problem for me...

but how can i write that string to a xml file....

ie i have to write that string to a file which is to be saved as
xml file...

is there any writeFile method available for doing this
process..

Or is there any source codes available in the net?

I'm a beginner to C++....

Can any one plzz explain me....

thanks..
senthil
Did you manage to get it to work when you tried ithere?
Dec 28 '06 #2

P: 61
Hai r035198x
ur conditions worked supervly
when i used for writing a string into a file...

But when i tried to writed the string which is fetched from the database
it is not working....

But anyway i will do the second step surely....

basically i'm working in the field of VC++....

But ur codings gave me an idea to write a file...

Hereafter i will do my work well...

thanks for ur support
senthil
Dec 29 '06 #3

10K+
P: 13,264
Hai r035198x
ur conditions worked supervly
when i used for writing a string into a file...

But when i tried to writed the string which is fetched from the database
it is not working....

But anyway i will do the second step surely....

basically i'm working in the field of VC++....

But ur codings gave me an idea to write a file...

Hereafter i will do my work well...

thanks for ur support
senthil
You need to explain how it's not working then so that people know how to help. Is the xml file being created at all?
Dec 29 '06 #4

P: 61
Hai
i am senthil...

i'm now working in the field of VC++...

I'm trying to retrive a string from the database and write it to a xml file...

i tried to write a string into a xml file...

But dont know how to retrive a string from the database and write it to a xml

file...

i tried the following codings for the above process..

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include <mysql.h> 
  3. #include <conio.h>
  4. #include <windows.h>
  5. #include<string.h>
  6.  
  7. #define host "192.168.0.2"
  8. #define username "root" 
  9. #define password "" 
  10. #define database "senthil"
  11.  
  12. void main()
  13. {
  14.     MYSQL *conn; 
  15.     conn = mysql_init(NULL);
  16.     mysql_real_connect(conn,host,username,password,database,0,NULL,0); 
  17.     MYSQL_RES *res_set; 
  18.     MYSQL_ROW row;        
  19.     unsigned int i=0; 
  20.     unsigned int j=0;        
  21.     mysql_query(conn,"SELECT * FROM sen1");
  22.     res_set = mysql_store_result(conn);
  23.     unsigned int numrows = mysql_num_rows(res_set);   
  24.    while ((row = mysql_fetch_row(res_set)) != NULL)
  25.      {
  26.                   HANDLE hFile; 
  27.                   DWORD wmWritten; 
  28.       char *strData =row[0];
  29.         hFile = CreateFile("C:\\test.xml",GENERIC_READ|GENERIC_WRITE, 
  30. FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); 
  31.        WriteFile(hFile,strData,(DWORD)(sizeof(strData)),&wmWritten,NULL); 
  32.        CloseHandle(hFile);                                   
  33.         }
  34.            mysql_close(conn);       
  35.            getch();
  36. }    
Here row[0] contains the string...

and i want to write it into the test.xml file...

Can any one plzz tell me how to retrive a string from the database
and write it to a file?

senthil
Dec 29 '06 #5

P: 61
Hai r035198x,

i explained in another post in c,c++ help with the codings i had developed for wrinting
a string to a xml file...

Plzz see that post and tell me...

thanks..
senthil
Dec 29 '06 #6

10K+
P: 13,264
Hai
i am senthil...

i'm now working in the field of VC++...

I'm trying to retrive a string from the database and write it to a xml file...

i tried to write a string into a xml file...

But dont know how to retrive a string from the database and write it to a xml

file...

i tried the following codings for the above process..

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include <mysql.h> 
  3. #include <conio.h>
  4. #include <windows.h>
  5. #include<string.h>
  6.  
  7. #define host "192.168.0.2"
  8. #define username "root" 
  9. #define password "" 
  10. #define database "senthil"
  11.  
  12. void main()
  13. {
  14. MYSQL *conn; 
  15. conn = mysql_init(NULL);
  16. mysql_real_connect(conn,host,username,password,database,0,NULL,0); 
  17. MYSQL_RES *res_set; 
  18. MYSQL_ROW row;     
  19. unsigned int i=0; 
  20. unsigned int j=0;     
  21. mysql_query(conn,"SELECT * FROM sen1");
  22. res_set = mysql_store_result(conn);
  23. unsigned int numrows = mysql_num_rows(res_set); 
  24. while ((row = mysql_fetch_row(res_set)) != NULL)
  25. {
  26. HANDLE hFile; 
  27. DWORD wmWritten; 
  28.      char *strData =row[0];
  29. hFile = CreateFile("C:\\test.xml",GENERIC_READ|GENERIC_WRITE, 
  30. FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); 
  31. WriteFile(hFile,strData,(DWORD)(sizeof(strData)),&wmWritten,NULL); 
  32. CloseHandle(hFile);          
  33.         }
  34. mysql_close(conn);     
  35.      getch();
  36. }    
Here row[0] contains the string...

and i want to write it into the test.xml file...

Can any one plzz tell me how to retrive a string from the database
and write it to a file?

senthil
In the above code from what I can see you are creating the file in a while loop. This is will create as many files as the data is retrieved from the database. You should create the file once outside the while loop maybe as the first step of the main method.
Dec 29 '06 #7

P: 61
Ya ok, what u r saying true....

But in the above program i'm using a database which is having

only one row...
plzz alter the program for writing to a text file...

Expand|Select|Wrap|Line Numbers
  1. that is my database like this...
  2. ---------------
  3. string (header)
  4. -------------------
  5.  
  6. senthil (row[0])
here only one row. when there is multiple rows it will create multiple files..

But here only one row contains a string senthil so it will create only one file..

In the output(for writing to a text file) The above program creates a text file
and writes the string... But when i opened that text file

it writes only the first four letters (sent)- this string is stored in the text file...

what shall i do for to store the full string...

will u plzz explain me...

thanks
senthil
Dec 29 '06 #8

10K+
P: 13,264
Ya ok, what u r saying true....

But in the above program i'm using a database which is having

only one row...
plzz alter the program for writing to a text file...

Expand|Select|Wrap|Line Numbers
  1. that is my database like this...
  2. ---------------
  3. string (header)
  4. -------------------
  5.  
  6. senthil (row[0])
here only one row. when there is multiple rows it will create multiple files..

But here only one row contains a string senthil so it will create only one file..

In the output(for writing to a text file) The above program creates a text file
and writes the string... But when i opened that text file

it writes only the first four letters (sent)- this string is stored in the text file...

what shall i do for to store the full string...

will u plzz explain me...

thanks
senthil
Can you put print statements to print
strData and
(DWORD)(sizeof(strData))

before writting to the file so that we know the values that they are holding.

If you are going to create an XML file you might want to include < > symbols
Dec 29 '06 #9

Post your reply

Sign in to post your reply or Sign up for a free account.