Adding elements with QXmlStreamWriter
So suppose we have an application that creates and writes and XML file using QXmlStreamWriter, and the XML will look like this:
Quote:
<xml>
<element>
<atrib>Something</atrib>
<atrib>Something else</atrib>
</element>
<element>
<atrib>Other</atrib>
<atrib>Do not know</atrib>
</element>
</xlm>
What I would neeed now is that other application opens the file and ands another <element> block so the file would look like this:
Quote:
<xml>
<element>
<atrib>Something</atrib>
<atrib>Something else</atrib>
</element>
<element>
<atrib>Other</atrib>
<atrib>Do not know</atrib>
</element>
<element>
<atrib>New</atrib>
<atrib>New</atrib>
</element>
</xlm>
Any guess
Re: Adding elements with QXmlStreamWriter
Quote:
Originally Posted by
hazardpeter
Any guess
Em, read the docs about QXmlStreamWriter?
Code:
QXmlStreamWriter stream(&output);
stream.setAutoFormatting(true);
stream.writeStartDocument();
// write your old data.
stream.writeStartElement("element");
stream.writeTextElement("atrib", "New");
stream.writeTextElement("atrib", "New");
stream.writeEndElement();
//...
stream.writeEndDocument();
Re: Adding elements with QXmlStreamWriter
I see, I had thought of that. I was just hopping for another way to do this but I don't mind xD. Thanks for the information!!
Re: Adding elements with QXmlStreamWriter
if you don't want to write all the old data yourself, you can consider using QDomDocument and adding there a new node and then simply save the whole via QDomNode::save().
Re: Adding elements with QXmlStreamWriter
Quote:
Originally Posted by
Lykurg
if you don't want to write all the old data yourself, you can consider using
QDomDocument and adding there a new node and then simply save the whole via
QDomNode::save().
Looks good, I will look in to that, thanks