QXML
-
How should the XML file look like at the end (supposing, it would work)?
-
@SGaist i just want to append my file
so after giving input all the data should be in the single <main> tag
but when ever i give input my app makes a new <main> tag which is wrong.. -
Well, your function creates a new main tag each time.
You either have to read your xml back, append your new book to the document and write the whole thing back to the file or modify the end of the file yourself (bad idea).
-
@Sgait
jux give me the idea how to add all the records in the same <main> tag?? -
It depends on when you want to add the record. Are you updating your xml file or are you creating a new XML file ?
-
i am actually updating the xml file
-
Since you're using DOM, read your XML back, search for your main element and append a new "book" child to it. Once done overwrite your file with the new content of the document.
-
Can u plz give me a code example
or simply edit my code.. -
- Read the xml file in a QDomDocument -> in the doc of QDomDocument
- Get "main" element -> in the doc of QDomElement
- Add a new element -> you already know how
- Write the document -> overwrite the complete file
-
hmmmm let me try this