Your proposal duplicates functionlity in two different classes.
In QDomDocument and in QDomElement. If gone with your approach, it'd further require duplication in QDomComment, QDomCDATASection, etc...
Also, another philosophical reason is clearly mentioned in the QDomDocument that,
"http://doc.qt.nokia.com/4.7/qdomdocument.html#details":http://doc.qt.nokia.com/4.7/qdomdocument.html#details
bq. Since elements, text nodes, comments, processing instructions, etc., cannot exist outside the context of a document, the document class also contains the factory functions needed to create these objects. The node objects created have an ownerDocument() function which associates them with the document within whose context they were created.
Make yourself a little helper class based on below pseudo.
@ctor(){
_doc = new QDomDocument();
}
~(){
delete _doc;
}
//Type is enum.
QDomNode* class::createNode(QDomNode* parent, const QString& nodeText, Type type)
{
switch(type){
case Element:
QDomElement* elem = _doc->createElement(nodeText);
parent->appendChild(*elem);
return elem;
...
}
}@