Regarding QDomDocument
-
HI volker
I edit window the code is appearing as nicely indented but when i see the preview it shows messed up indentation.
-
Why do you not construct the whole XML using QDom methods but open an XML template and try to modify and duplicate this? This is quite strange at best, as you have the structure of the XML hardcoded in your method anyways (by means of the huge if/else blocks).
-
Hi volker
I know it is redundant way,but is it possible to get the result withthe same.
-
"QDomNode::cloneNode() ":http://doc.qt.nokia.com/4.7/qdomnode.html#cloneNode should be your friend.
-
Rajveer, why do you keep opening topics on the same issue?
http://developer.qt.nokia.com/forums/viewthread/9240/
http://developer.qt.nokia.com/forums/viewthread/8947/
http://developer.qt.nokia.com/forums/viewthread/7905/
http://developer.qt.nokia.com/forums/viewthread/7704/You don't seem to be making much progress, to be honest.
-
Hi All
My XML tag format is as shown below
@
<INFO>
<FIELD name = "ONE"></FIELD>
.
.
.
600
</INFO>My final XML file should be like this
<?xml version="1.0"?>
<root>
<INFO>....</INFO>
<INFO>....</INFO>
<INFO>....</INFO>
<INFO>....</INFO>
.
.
.
50000
</root>
@
I want to create a xml file with 50000 tags as shown above.Below is my code
@
QDomDocument mainDoc;
QDomProcessingInstruction instr = mainDoc.createProcessingInstruction("xml","version="1.0"");
mainDoc.appendChild(instr);
QDomElement root = mainDoc.createElement("root");
mainDoc.appendChild(root);QDomDocument doc; QString errMsg; int errLine; int errCol;
QString strItemTemplateData;//In this i have my Tag INFO stored
if (!doc.setContent(strItemTemplateData,false,&errMsg,&errLine,&errCol))
{
qDebug() << "Error in XML File format" <<endl;
}
for(int i=0;i<50000;i++)
{
QDomNode clonedNode = doc.cloneNode(true);
root.appendChild(clonedNode);
}
QFile generatedFile(strXMLFileName);
if (!generatedFile.open(QIODevice::WriteOnly))
{
qDebug() << "Error in Filet" <<endl;
return;
}
QTextStream textStream(&generatedFile);
mainDoc.save(textStream,4);
generatedFile.close();
@My code above is performing very slow i.e it is taking lot of time & also some times it is crashing.
Can anybody tell me how to create such a big file with good performance.
And While creating the TAGS i have to set values for each TAG items for which i have to check each attribute value and than set it.
eg:
@
<FIELD name="ONE">USA</FIELD>
@[EDIT: three dots are enough, Volker]
-
QDomDocument is not the way how to handle big XML documents, but you have been told numerous times:
http://developer.qt.nokia.com/forums/viewthread/9483/
http://developer.qt.nokia.com/forums/viewthread/9240/
http://developer.qt.nokia.com/forums/viewthread/8947/
http://developer.qt.nokia.com/forums/viewthread/7905/
http://developer.qt.nokia.com/forums/viewthread/7704/So - please - stop creating topics on the same issue over and over again and stick to the ones you've already created.
-
Hi Lukas
Not in anyone of the links u pasted has mentioned that
QDomDocument is not the way how to handle big XML documents
So please see my question and purpose of my question. -
You may ask multiple questions in the same topic as long as they are related. There is no need to create a new one.
Your application is slow and/or crashes because either your code is broken or for the simple fact that QDomDocument represents the whole XML structure in memory. If your XML structure contains hundreds of thousands of nodes you simply run out of memory and your application crashes. This is why you've been shown how to use QXmlStreamReader / QXmlStreamWriter instead which does not suffer from this problem and/or how to restructure your XML design so it isn't that bloated.
-
Moderator's note:
I have merged the two threads "XML File generation using QDomDocument" (was http://developer.qt.nokia.com/forums/viewthread/9483/) from September and "Problem in creating XML file using QDomDocument" (http://developer.qt.nokia.com/forums/viewthread/10663/) from today into this thread. The all are on the same topic.
Please stop creating new threads on the same topic.
Also, please mind to format your code so that it can be read easily. This includes proper indenting. I doubt that many people take care have a look your code anymore if it's so hard to read.
Overall, please read and understand: http://www.catb.org/~esr/faqs/smart-questions.html