Results 1 to 4 of 4

Thread: QDomDocument Speed by 24MB file

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QDomDocument Speed by 24MB file

    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 

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDomDocument Speed by 24MB file

    Why do you read line by line in a QString, when you can use:
    bool setContent ( QIODevice * dev, QString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )?

    QFile is a subclass of QIODevice so you can pass the file after you open in instead of the QTextStream. Should be considerably
    faster.

    Regards

  3. The following user says thank you to marcel for this useful post:

    patrik08 (30th April 2007)

  4. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDomDocument Speed by 24MB file

    Quote Originally Posted by marcel View Post
    Why do you read line by line in a QString, when you can use:
    bool setContent ( QIODevice * dev, QString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )?

    QFile is a subclass of QIODevice so you can pass the file after you open in instead of the QTextStream. Should be considerably
    faster.

    Regards

    Yes now the console stay frozen 40 sec. .... and before I see turn [-\|/-] .. chars .

    Have you find a class to display Postcript file? or PDF? .. I put XPDF Libs on ice to Window...

    http://poppler.freedesktop.org/ have a QT4 libs ... but i found bug on automake from mingw MSYS .... this gay make it only to build on automake autoconf & other tools... and not simply a *.pro file ...

  5. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDomDocument Speed by 24MB file

    Yes now the console stay frozen 40 sec. .... and before I see turn [-\|/-] .. chars
    Well, it is a pretty big file... But still, is faster than you said it was before... I am not sure if you can make it load faster. Probably this is the best solution, because if you were to load it in an intermediate buffer, you would still loose some time with the loading part. Then, the QDomDocument would still have to parse your buffer, so you're back at square one...

    To provide feedback to the user while loading large files, you could do the loading in a separate thread ( or use a QTimer and notify the user every 5 secs, let's say, that the file is still loading ). of course, this depends on how much need the user has to be notified .

    Have you find a class to display Postcript file? or PDF? .. I put XPDF Libs on ice to Window...
    No, unfortunately. I still plan to modify xpdf on my own and integrate it with qt, but this as soon as I find some spare time ( a lot of free time ).
    I don't know of any other pdf library as complete as xpdf out there ( well, except the Adobe pdf Library ).

    Regards

Similar Threads

  1. Sending Binary File with QFTP
    By nbkhwjm in forum Newbie
    Replies: 2
    Last Post: 7th March 2007, 18:10
  2. How To Extract A File
    By deekayt in forum General Programming
    Replies: 7
    Last Post: 5th December 2006, 18:27
  3. SQLite-DB in a qrc file
    By Lykurg in forum Qt Programming
    Replies: 5
    Last Post: 31st July 2006, 19:24
  4. Replies: 11
    Last Post: 4th July 2006, 15:09
  5. Adding whitespace in QDomDocument
    By jakamph in forum Newbie
    Replies: 4
    Last Post: 6th February 2006, 22:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.