2

如何在 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>
4

1 回答 1

4

是的,你可以直接在QXmlStreamWriter的设备上使用write方法;例子:

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

于 2015-05-14T21:33:37.873 回答