【发布时间】:2011-10-08 21:18:16
【问题描述】:
我需要编辑 QDomElement 的文本 - 例如
我有一个 XML 文件,其内容为 -
<root>
<firstchild>Edit text here</firstchild>
</root>
如何编辑子元素<firstchild>的文字?
我在 Qt 4.7 中提供的 QDomDocument 类描述的 QDomElement 中没有看到任何函数
Edit1 - 我正在添加更多细节。
我需要读取、修改和保存一个 xml 文件。文件格式如下-
<root>
<firstchild>Edit text here</firstchild>
</root>
需要编辑element的值。我读取xml文件的代码是-
QFile xmlFile(".\\iWantToEdit.xml"); xmlFile.open(QIODevice::ReadWrite); QByteArray xmlData(xmlFile.readAll()); QDomDocument doc; doc.setContent(xmlData);// 读取必要的值
// 写回修改后的值?
注意:我尝试将 QDomElement 转换为 QDomNode 并使用函数 setNodeValue()。但是它不适用于 QDomElement。
我们非常欢迎任何建议、代码示例、链接。
【问题讨论】: