gpt4 book ai didi

c++ - 使用 QXmlStreamWriter 编写 XML 代码

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:28:04 25 4
gpt4 key购买 nike

如何在 XML 中写入 XML 文本?

QXmlStreamWriter xmlWriter(&file);
(...)
QString xmlCode = "This is a <b>XML</b> code. And should be written as is it";
xmlWriter.writeStartElement("start");
xmlWriter.writeCharacters(xmlCode);
xmlWriter.writeEndElement();

输出应该是:

<start>
This is a <b>XML</b> code. And should be written as is it
</start>

最佳答案

是的,您可以使用 write method on the QXmlStreamWriter's直接设备;示例:

QXmlStreamWriter xmlWriter(&file);
xmlWriter.writeStartElement("start");
xmlWriter.writeCharacters(""); // This will open and close <start> tag correctly
xmlWriter.device()->write(xmlCode.toLatin1().constData(), xmlCode.length());
xmlWriter.writeEndElement();

这里也有人建议:http://www.qtcentre.org/threads/60045-writing-raw-data-into-xml-sub-node

关于c++ - 使用 QXmlStreamWriter 编写 XML 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16016059/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com