PDA

View Full Version : Problem in updating XML file



Qt_Kid
26th February 2011, 14:07
Dear Members,

I've created a sample application to save data in xml. Fist time it is saving data properly. But next time it is corrupting the file. I'm not able to find the problem. Here with I've attached the code. Can any body tell me what is problem in the code.

N.B. : the xml file will create in C drive with name VCS.xml

Thank you.

squidge
26th February 2011, 15:12
What do you mean by "it is corrupting the file" ?

What do you expect? What is the actual result?

Qt_Kid
26th February 2011, 15:19
What do you mean by "it is corrupting the file" ?

What do you expect? What is the actual result?

Thank you very much fro the quick reply.
First time if i'm entering data like
name : Alex
IP : 1.0.0.1
Group : Friend
then its creating the file and updating the data.
If second time if i'm updating data like
name : Jack
IP : 1.0.0.1
Group : Friend
and I'm opening the file it is not displaying any data.

squidge
26th February 2011, 17:41
So after the first run of your application, the contents of the output file is OK.

After the second run of your application, the contents of the output file is empty.

Correct?

Qt_Kid
27th February 2011, 05:08
So after the first run of your application, the contents of the output file is OK.

After the second run of your application, the contents of the output file is empty.

Correct?

No its filling data. If you ll open the file in note pad u can find there is some data.But if u r opening with internet explorer then its showing error. Here with I've attached the code. If u ll run and fill the data, the file will be creaed on C:\VCS folder.

wysota
27th February 2011, 08:57
Is "some data" the data you expect?

Qt_Kid
27th February 2011, 09:15
Is "some data" the data you expect?
Yes.

I wanna data like

Name : john
Ip : 1.0.0.1
Group : Company

Name : Alex
IP : 1.0.0.2
Group : Company

Thank You.

squidge
27th February 2011, 09:32
But the first time internet explorer says the data is ok?

Sorry, we are still struggling to understand what you mean.

Maybe you could post the two xml files - first and second.

Qt_Kid
27th February 2011, 09:48
But the first time internet explorer says the data is ok?

Sorry, we are still struggling to understand what you mean.

Maybe you could post the two xml files - first and second.


Here with I've attached two files. And code already i've uploaded above. If u'll run the code, u can find the file also.
Thank you.

wysota
27th February 2011, 09:54
After opening the second file it should be obvious for you why the file is wrong. You can't just append another xml document to the first one and expect them to magically merge into one document. You need to update the first document with additional tags that you currently have in the second document. You should also learn how does a well formed xml file should look like.

Qt_Kid
27th February 2011, 10:13
After opening the second file it should be obvious for you why the file is wrong. You can't just append another xml document to the first one and expect them to magically merge into one document. You need to update the first document with additional tags that you currently have in the second document. You should also learn how does a well formed xml file should look like.

Thank you very much wysota. Can you please tell me how to do this? I'm new to Qt and first time i'm working with XML file. So your small help will help a lot.

wysota
27th February 2011, 10:54
Take a look at QDomDocument docs. There is an example of modifying a document and a couple of links to xml specs.