I have each week big xml file to read, QFile have 2 minute to open file.
setContent from QDomDocument have 30 sec. to parse this file.
On read xml QSqlDatabase play all attribute to db on 15 sec. ...

is the QXmlDefaultHandler faster? or How?



Qt Code:
  1. void PlaySincro::ValidateFile( QString xmlfile )
  2. {
  3. QFileInfo fi(xmlfile);
  4. bool cvalid = true;
  5. QString re;
  6. QFile file( xmlfile );
  7. const char *dat;
  8.  
  9. std::cout << "### loading file wait... " << fi.fileName().toAscii().data() << " Size/" << BiteorMega(fi.size()).toAscii().data() << std::endl;
  10.  
  11. if( file.open( QFile::ReadOnly | QFile::Text ) ) {
  12. QTextStream in( &file );
  13. int cur = 0;
  14.  
  15. while( ! in.atEnd() ) {
  16. QString line = QString( in.readLine() );
  17. re.append(line);
  18. cur++;
  19.  
  20. switch(cur)
  21. {
  22. case 1:
  23. dat ="-";
  24. break;
  25. case 2:
  26. dat ="\\";
  27. break;
  28. case 3:
  29. dat ="|";
  30. break;
  31. case 4:
  32. dat ="/";
  33. cur = 0;
  34. break;
  35. }
  36.  
  37. std::cout << "Read file " << fi.fileName().toAscii().data() << " [" << dat << "]\r";
  38. fflush ( stdin );
  39.  
  40. }
  41. }
  42.  
  43. Qxml doc; /* class Qxml : public QDomDocument */
  44. QString errorStr;
  45. int errorLine, errorColumn, position;
  46.  
  47. if (!doc.setContent(re,false, &errorStr, &errorLine, &errorColumn)) {
  48. std::cout << "### Unable to read XML file! errorLine" << errorLine << " errorColumn" << errorColumn << std::endl;
  49. return;
  50. }
  51.  
  52. QDomElement root = doc.root();
  53. QDomElement query = root.firstChildElement("query");
  54. QString user = doc.GetAtt(query,"user");
  55. QString summs = doc.GetAtt(query,"sumrow");
  56. QString cools = doc.GetAtt(query,"sumcool");
  57. QString data = doc.GetAtt(root,"build");
  58. QString org = doc.GetAtt(root,"org");
  59.  
  60. if (data.size() < 1 && user.size() < 1 && summs.size() < 1 && cools.size() < 1 && org.size() < 1) {
  61. cvalid = false;
  62. }
  63.  
  64. if (root.tagName() != "odbc_root" ) {
  65. cvalid = false;
  66. }
  67.  
  68.  
  69. if (cvalid) {
  70. std::cout << "###" << xmlfile.toAscii().data() << " valid Ok! From " << user.toAscii().data() << std::endl;
  71. PlayFileDom(root,org);
  72. doc.clear();
  73. } else {
  74. std::cout << "###" << xmlfile.toAscii().data() << " not valid!" << std::endl;
  75. }
  76. }
To copy to clipboard, switch view to plain text mode