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
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);
QString xmlAddress=projectAddress;
xmlAddress+="//";
xmlAddress+=projectName;
xmlAddress+=".drdp";//项目的åŽç¼€å为.drdp
QDomDocument doc;
QDomElement project=doc.createElement("Project");
QDomElement projectInformation=doc.createElement("ProjectInformation");
QDomElement createTime=doc.createElement("CreateTime");
QDomElement name=doc.createElement("Name");
QDomElement author=doc.createElement("Author");
QDomElement description=doc.createElement("Description");
QDomElement unit=doc.createElement("Unit");
QDomElement type=doc.createElement("Type");
QDomElement files=doc.createElement("Files");
QDomElement chart2d=doc.createElement("Chart2D");
QDomElement chart3d=doc.createElement("Chart3D");
QDomElement data=doc.createElement("Data");
QDomElement databases=doc.createElement("Databases");
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());
QTextStream out(&xmlAddress);
doc.save(out,4);
To copy to clipboard, switch view to plain text mode
Bookmarks