QDomDocumen save method doesn't work!
i want to create a file and write some xml code in it use the below code like this ,but it don't save anything ,anyone could help me:confused::confused::confused:
Code:
xmlAddress+="//";
xmlAddress+=projectName;
xmlAddress+=".drdp";//项目的åŽç¼€å为.drdp
QDomElement projectInformation
=doc.
createElement("ProjectInformation");
QDomElement createTime
=doc.
createElement("CreateTime");
QDomElement description
=doc.
createElement("Description");
doc.appendChild(project);
project.appendChild(projectInformation);
project.appendChild(files);
project.appendChild(databases);
projectInformation.appendChild(createTime);
projectInformation.appendChild(name);
projectInformation.appendChild(author);
projectInformation.appendChild(description);
projectInformation.appendChild(unit);
projectInformation.appendChild(type);
QDomText txtCreateTime
=doc.
createTextNode(projectCreateTime.
toString(Qt
::DateFormat::ISODate));
QDomText txtAuthor
=doc.
createTextNode(projectAuthor
);
QDomText txtName
=doc.
createTextNode(projectName
);
QDomText txtDescription
=doc.
createTextNode(projectDescription
);
QDomText txtType
=doc.
createTextNode("TextType");
QDomText txtUnit
=doc.
createTextNode("TextUnit");
createTime.appendChild(txtCreateTime);
name.appendChild(txtName);
author.appendChild(txtAuthor);
description.appendChild(txtDescription);
unit.appendChild(txtUnit);
type.appendChild(txtType);
QDomNode xmlNode
= doc.
createProcessingInstruction("xml",
"version=\"1.0\" encoding=\"utf-8\"");
doc.insertBefore(xmlNode, doc.firstChild());
doc.save(out,4);
Re: QDomDocumen save method doesn't work!
Well, it is perfectly saved, but not where you expect it! It is saved in your QString xmlAddress. If you want to save it to a file, specified by xmlAddress, you have to use QFile first!
And did you noticed, that you have used the wrong tags to indicate that your text is c++ code? Please use the [code] tags next time, which makes your code much more readable.
Re: QDomDocumen save method doesn't work!
thank you i have correct this probrem
Quote:
Originally Posted by
Lykurg
Well, it is perfectly saved, but not where you expect it! It is saved in your QString xmlAddress. If you want to save it to a file, specified by xmlAddress, you have to use QFile first!
And did you noticed, that you have used the wrong tags to indicate that your text is c++ code? Please use the [code] tags next time, which makes your code much more readable.