我需要編輯QDomElement的文本 - 例如編輯QDomElement的值?
我有一個XML文件,其作爲內容 -
<root>
<firstchild>Edit text here</firstchild>
</root>
如何編輯的子元素<firstchild>
的文字?
我看不出有任何的功能在Qt的4.7
EDIT1提供的QDomDocument的QDomElement類的描述 - 我加入了更多的細節。
我需要讀取,修改和保存一個xml文件。到該文件的格式如下 -
<root>
<firstchild>Edit text here</firstchild>
</root>
元素的值需要是edited.I代碼來讀取該XML文件是 -
QFile xmlFile(".\\iWantToEdit.xml"); xmlFile.open(QIODevice::ReadWrite); QByteArray xmlData(xmlFile.readAll()); QDomDocument doc; doc.setContent(xmlData);
//讀取必要的值
//寫回修改後的值?
注:我試圖將QDomElement轉換爲QDomNode並使用函數setNodeValue()。但是它不適用於QDomElement。
任何建議,代碼示例,鏈接,我們非常歡迎。
這適用於輕微的修改。謝謝。 –
@永遠的學習者:不要忘記了解賞金! – Goz
實際上,裏面的文本是一個文本節點,所以你可以這樣做,如下所示:doc.documentElement()。firstChildElement(「firstchild」)。firstChild()。setNodeValue(「new text」); //注意額外的firstChild()查詢 – Petar