How to insert a child element in an existing element
-
I want to insert an child element in an existing element in an existing text file. my file is like this:
@<?xml version="1.0" encoding="UTF-8"?>
<passwords name="shubham the ultimate champion">
<account>
<name>shubham maheshwari</name>
<password>sdfsdf</password>
<account_type>forum</account_type>
<account_name>shubham1</account_name>
<home_page>ohloglsfosdf</home_page>
</account>
<account>
<name>siddharth maheshwari</name>
<password>adfadf</password>
<account_type>devnet</account_type>
<account_name>sidharth1</account_name>
<home_page>jkjskdfjdfsk</home_page>
</account>
</passwords>@
I have tried many things i want the best easy simple and fast way to insert a new tag named "account" in "passwords" -
Hi, ~developer!
Why can't you fetch DOM and append dom child into
passwords
with standart QtXml module's functional? -
@tucnak please a small exmaple code or hint or classes
-
[quote author="developer" date="1352531950"]@tucnak please a small exmaple code or hint or classes[/quote]
Create "QDomDocument":http://qt-project.org/doc/qt-5.0/qdomdocument.html] refering to the file which has your XML.
Parse xml as DOM tree
Insert "QDomNode":http://qt-project.org/doc/qt-5.0/qdomnode.html after another node you need to find
-
ok i have tried a lot please tell me how to parase xml as dom tree
-
Use QDomNode nextSibling() while nextSibling's QDomNode will have the tag name 'passwords' and append to it your QDomNode.
References:
http://qt-project.org/doc/qt-4.8/qdomdocument.html#createElement
http://qt-project.org/doc/qt-4.8/qdomdocument.html#toString
http://doc.qt.digia.com/qt/qdomnode.html#appendChild
http://doc.qt.digia.com/qt/qdomnode.html#nextSiblingAnd read a bit about QtXml.