PDA

View Full Version : Split QDomDocument to new QDomDocument



estanisgeyer
27th January 2009, 20:10
Hi guys,

I have an xml document and I need copy part of the content to a new xml document, following an example:



<?xml encoding="utf-8" ?>
<Library>
<Location>
<Test> <---- split here
.....
.....
</Test>
<Test2>
.....
.....
</Test2>
<Location>
</Library>


I want to create a new document xml taking the "Test" tag as my root element. How can I do that? The next few snippets of code:



QByteArray b;
...
QDomDocument xml;
xml.setContent(b); // It's ok, its working.
QDomElement root = xml.documentElement();
QDomNode node = root.firstChild();
...


Thanks,

Marcelo E. Geyer

jpn
27th January 2009, 21:06
Try with QDomNode::save().

estanisgeyer
27th January 2009, 21:14
Ok, I want to put the contents of that xml in a QByteArray or QString, QDomNode::toDocument( ) thought to use, but is returning empty.

jpn
28th January 2009, 07:06
Ok, I want to put the contents of that xml in a QByteArray or QString, QDomNode::toDocument( ) thought to use, but is returning empty.
Because the node is not the document node. QDomNode::toDocument() docs clearly states:


Converts a QDomNode into a QDomDocument. If the node is not a document the returned object will be null.

wysota
28th January 2009, 09:59
You can also use QDomDocument::importNode().