Results 1 to 8 of 8

Thread: Static libs Libtidy on QT4 clean html/xml

  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 Static libs Libtidy on QT4 clean html/xml

    I have build successful libtidy on qt4

    Now how i cann translate this C++ sample to make

    bool Clean_Code_utf8(QString incomming_file, QString output_file, QString config_file)

    Have anibody experience on tidy? I understand tidy only from php....

    Qt Code:
    1. #include <tidy.h>
    2. #include <buffio.h>
    3. #include <stdio.h>
    4. #include <errno.h>
    5.  
    6.  
    7. int main(int argc, char **argv )
    8. {
    9. const char* input = "<title>Foo</title><p>Foo!";
    10. TidyBuffer output = {0};
    11. TidyBuffer errbuf = {0};
    12. int rc = -1;
    13. Bool ok;
    14.  
    15. TidyDoc tdoc = tidyCreate(); // Initialize "document"
    16. printf( "Tidying:\t%s\n", input );
    17.  
    18. ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes ); // Convert to XHTML
    19. if ( ok )
    20. rc = tidySetErrorBuffer( tdoc, &errbuf ); // Capture diagnostics
    21. if ( rc >= 0 )
    22. rc = tidyParseString( tdoc, input ); // Parse the input
    23. if ( rc >= 0 )
    24. rc = tidyCleanAndRepair( tdoc ); // Tidy it up!
    25. if ( rc >= 0 )
    26. rc = tidyRunDiagnostics( tdoc ); // Kvetch
    27. if ( rc > 1 ) // If error, force output.
    28. rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 );
    29. if ( rc >= 0 )
    30. rc = tidySaveBuffer( tdoc, &output ); // Pretty Print
    31.  
    32. if ( rc >= 0 )
    33. {
    34. if ( rc > 0 )
    35. printf( "\nDiagnostics:\n\n%s", errbuf.bp );
    36. printf( "\nAnd here is the result:\n\n%s", output.bp );
    37. }
    38. else
    39. printf( "A severe error (%d) occurred.\n", rc );
    40.  
    41. tidyBufFree( &output );
    42. tidyBufFree( &errbuf );
    43. tidyRelease( tdoc );
    44. return rc;
    45. }
    To copy to clipboard, switch view to plain text mode 

    Subversion dir...
    svn co http://ciz.ch/svnciz/forms_shop/lib_tidy_src/ libtydy
    Compile ok on window...


    pro file ....
    Qt Code:
    1. DEPENDPATH += . include
    2. INCLUDEPATH += . include
    3. TEMPLATE =lib
    4. CONFIG += qt warn_off release staticlib
    5. LANGUAGE = C++
    6. #DEFINES -= UNICODE
    7. DEFINES += NDEBUG THREAD_SAFE=1 TEMP_STORE=2
    8.  
    9. DESTDIR = ../all_os_libs/
    10. win32:TARGET = tidy
    11. unix:TARGET = tidy
    12. mac:TARGET = tidy
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Earth (Terra)
    Posts
    87
    Thanks
    4
    Thanked 6 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Static libs Libtidy on QT4 clean html/xml

    Fundamentally, assuming the code is working, you simply need to re-encapsulate it in a function, open the "incomming_file", bring it into a buffer and feed it to tidy. Then take the output buffer and write it out to the "output_file" specified in the second arg.

    What's the "config_file" arg for? If it contains tidy configuration directives (projecting, here), you'll have to open that up, parse out the directives, and then set up a construct to set the directives found.

    rickb

  3. #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: Static libs Libtidy on QT4 clean html/xml

    tidy config file... preference html or xml and so show-warnings: no ....

    so i can parse html or xml utf8 or iso...

    Qt Code:
    1. // sample config file for HTML tidy
    2. indent: auto
    3. indent-spaces: 2
    4. wrap: 72
    5. markup: yes
    6. output-xml: no
    7. input-xml: no
    8. show-warnings: yes
    9. numeric-entities: yes
    10. quote-marks: yes
    11. quote-nbsp: yes
    12. quote-ampersand: no
    13. break-before-br: no
    14. uppercase-tags: no
    15. uppercase-attributes: no
    16. char-encoding: latin1
    17. new-inline-tags: cfif, cfelse, math, mroot,
    18. mrow, mi, mn, mo, msqrt, mfrac, msubsup, munderover,
    19. munder, mover, mmultiscripts, msup, msub, mtext,
    20. mprescripts, mtable, mtr, mtd, mth
    21. new-blocklevel-tags: cfoutput, cfquery
    22. new-empty-tags: cfelse
    To copy to clipboard, switch view to plain text mode 


    Tanks i try .... if a problem i post on c++ forum...

  4. #4
    Join Date
    Jan 2006
    Location
    Earth (Terra)
    Posts
    87
    Thanks
    4
    Thanked 6 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Static libs Libtidy on QT4 clean html/xml

    Exactly on the config file.

    Make sure you also test for invalid configuration keys, so you can flag up error.

    rickb

  5. #5
    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: Static libs Libtidy on QT4 clean html/xml

    user not write config file....
    Is a CMS - CRM ... and must have clean xml report to xslt's (pdfs) and clean xhtml to webpage...

    But i think is possibel to make chekbox GUI to write a new config file...

  6. #6
    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: Static libs Libtidy on QT4 clean html/xml

    Is running .... and clean file.... so....

    Qt Code:
    1. /* similar command http://php.net/tidy */
    2. Tidy::Tidy()
    3. {
    4. status = 0;
    5. ErrorMSG ="";
    6. doc = tidyCreate();
    7. }
    8.  
    9. /* prepare config tidy config file */
    10. bool Tidy::SetUp(QString configfile)
    11. {
    12. qDebug() << "### load config.... " << configfile;
    13. ConfigFileTidy = configfile;
    14. status = tidyLoadConfig( doc, qtchar(configfile) ); /* http://ch2.php.net/manual/de/function.tidy-load-config.php */
    15. if ( status != 0 ) {
    16. ErrorMSG ="Not possibel to load Config File!";
    17. return false;
    18. } else {
    19. return true;
    20. }
    21. }
    22. /* QString clean file inputfile and put to outfile */
    23. bool Tidy::CleanTidy(QString inputfile, QString outfile)
    24. {
    25. qDebug() << "### load inputfile.... " << inputfile;
    26. qDebug() << "### load outfile.... " << outfile;
    27. if (!ConfigFileTidy.size() > 0 && status != 0) {
    28. ErrorMSG ="Set up a config file!";
    29. return false;
    30. }
    31. Bool ok;
    32. int rc = -1;
    33. /*TidyBuffer output;*/
    34. TidyBuffer errbuf;
    35. QString resultwork;
    36. QString inside = "";
    37. QFile file(inputfile);
    38. if (file.exists()) {
    39. if (file.open(QFile::ReadOnly | QFile::Text)) {
    40. inside =file.readAll();
    41. file.close();
    42. }
    43. } else {
    44. ErrorMSG ="No input file found!";
    45. }
    46. QByteArray ba = inside.toAscii();
    47. /*qDebug() << "### load input.... " << ba.data();*/
    48.  
    49. qDebug() << "### steep 1 ok ";
    50. rc = tidyParseString( doc, ba.data() ); /* http://ch2.php.net/manual/de/function.tidy-parse-string.php*/
    51. qDebug() << "### steep 1a ok " << rc; /* rc become error message */
    52. if ( rc > 0 ) {
    53. ErrorMSG ="Success";
    54. qDebug() << "### steep 2 ok ";
    55. rc = tidySaveFile( doc, qtchar(outfile) );
    56. qDebug() << "### steep 3 ok " << rc;
    57. tidyRelease( doc );
    58. return true;
    59. }
    60.  
    61.  
    62. /*tidyBufFree( &errbuf );*/
    63. tidyRelease( doc );
    64. return false;
    65. }
    66. /* QString to const char* */
    67. const char* Tidy::qtchar( QString xml )
    68. {
    69. QByteArray ba = xml.toAscii();
    70. const char* hack = ba.data();
    71. return hack;
    72. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jan 2006
    Location
    Earth (Terra)
    Posts
    87
    Thanks
    4
    Thanked 6 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Static libs Libtidy on QT4 clean html/xml

    Great that you got it working.

    Just looking over the code, I don't see where the configfile is used. It doesn't look like you're processing the directives or making set calls, anywhere.

    Maybe it's not necessary?

    Oops - on re-examination, I see where it's getting submitted to the tidy object.
    Never mind.

    Carry on,
    rickb
    Last edited by rickbsgu; 29th May 2006 at 16:09.

  8. #8
    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: Static libs Libtidy on QT4 clean html/xml

    Yes ist not need .... default file ...
    Each config have a default value ...

    numeric-entities: yes ..... ecc...

    If You chanche default value .... is possibel to write each line ... same as php....
    but I wand to add & write my own tag 18 pieces.... xml / xslt and a list is long.... so i make a file....

    default value i found here.... http://perens.com/Slides/Copenhagen0/tidy.conf

Similar Threads

  1. Qt libs static and dynamic
    By conexion2000 in forum Installation and Deployment
    Replies: 3
    Last Post: 24th May 2006, 09:09

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
  •  
Qt is a trademark of The Qt Company.