QXmlStreamWriter 写入xml 文件

前端之家收集整理的这篇文章主要介绍了QXmlStreamWriter 写入xml 文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


QString fileName(tr("output.xml"));
QFile file(fileName);
if (!file.open(QFile::WriteOnly | QFile::Text))
{
	std::cerr << "Error: Cannot open file" << std::endl;
}

QString strA(tr("A")),strB(tr("B")),strC(tr("C")),strD(tr("D"));

QXmlStreamWriter xmlWriter(&file);
xmlWriter.setAutoFormatting(true);
xmlWriter.writeStartDocument();
	xmlWriter.writeStartElement("result");
		xmlWriter.writeStartElement("A");
			xmlWriter.writeCharacters(strA);
		xmlWriter.writeEndElement();
		xmlWriter.writeStartElement("B");
			xmlWriter.writeCharacters(strB);
		xmlWriter.writeEndElement();
		xmlWriter.writeStartElement("C");
			xmlWriter.writeCharacters(strC);
		xmlWriter.writeEndElement();
		xmlWriter.writeStartElement("D");
			xmlWriter.writeCharacters(strD);
		xmlWriter.writeEndElement();
	xmlWriter.writeEndElement();
xmlWriter.writeEndDocument();
file.close();
原文链接:https://www.f2er.com/xml/295887.html

猜你在找的XML相关文章