
Originally Posted by
Dangelo
Hi guys, I'm newbie at everything, so please be patient.
I'm trying to save Users data (like password and login) in a XML, reading and appending in this file whenever I need to.
I started to use only QXMLStream to write, but then with a little research I found out that using QDomDocument would be more simple and easy.
So, my intent is to create a XML File with data of users, and have the possibility to read, add and remove users from the xml.
I already tried many things, the last one was write and read with QDomDocument, but I keep getting a error of ""unexpected end of file" 1 1 " when I try "doc.setContent" function. Well, I could solve that by pre-creating a XML File with just the root element, using a xmlWriter (QXmlWriteStream), but when I do that I got a wrong Xml File, like:
(when I just initialize the xml to don't fall in to the "unexpected end of file" 1 1 " error)
<?xml version="1.0" encoding="UTF-8"?><Users/>
until here it's ok, I have a xml with the empty root element Users.
When I start to add a user, and use the QDomDocument functions:
<?xml version="1.0" encoding="UTF-8"?><Users/>
<?xml version='1.0' encoding='UTF-8'?>
<Users>
<user/>
</Users>
As you can see, he doubles the document, dont know why, probably when I save the changes with doc->save...but I don't know other way to save changes in a file with QdomDocument
the code:
QDomElement root = doc->documentElement();
qDebug()<< root.tagName();
QDomElement user = doc->createElement("user");
root.appendChild(user);
QTextStream out(&database);
doc->save(out, Indent);
database.close();
So that's it, I already tried many things, but none of them gave me a right xml file, even something close to that (a xml with multiple root elements, but with right data and formatting.
Sorry for my bad english, I'm brazilian and they don't teach it very well here ;p....And if I did something wrong making this post, please warn me, I'll certainly do it right next time.
Regards.
Bookmarks