Results 1 to 10 of 10

Thread: QTextStream capture stdout from xsltParseStylesheetFile

  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 QTextStream capture stdout from xsltParseStylesheetFile

    a external lib funktion write to stdout i see on debug mode this...
    cur = xsltParseStylesheetFile( (const xmlChar*)gocharxslt.data() );

    How i can capture this important error to say user error line xx tag ...

    wenn i start a QTextStream out(stdout); is only write to stdout
    i grab only ###start#### & #### end ##### and not stdout from xsltParseStylesheetFile on php i use http://php.net/ob-start and grab all or partial...

    Qt Code:
    1. qDebug() << "### SHORTFILE " << SHORTFILE;
    2. qDebug() << "### DATA_FILE_XML " << DATA_FILE_XML;
    3. qDebug() << "### DATA_CONVERTER " << DATA_CONVERTER;
    4. QString actualxslt = xsl_area->document()->toPlainText();
    5. fxslt = db->file_put_contents(DATA_CONVERTER,actualxslt);
    6. QString actualxml = xml_area->document()->toPlainText();
    7. fxml = db->file_put_contents(DATA_FILE_XML,actualxslt);
    8.  
    9. /* ######################################### */
    10. xsltStylesheetPtr cur = NULL;
    11. xmlDocPtr doc, outputDoc;
    12. xmlSubstituteEntitiesDefault(1);
    13. /* ######################################### */
    14. QTextStream out(stdout);
    15. out << "######################start############################\n";
    16. QByteArray gocharxslt = DATA_CONVERTER.toAscii();
    17. cur = xsltParseStylesheetFile( (const xmlChar*)gocharxslt.data() );
    18. if (!cur) {
    19. xslt_error = "XSLT! [7] XsltParseStylesheetFile Failture files =>"+DATA_CONVERTER;
    20. }
    21. out << "\n#######################stop###########################\n" << endl;
    22. capturesdout = out.readAll();
    23. out.flush();
    24. qDebug() << "### CUR error " << cur;
    25. qDebug() << "### capturesdout error " << capturesdout;
    26. xsltFreeStylesheet(cur);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    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: QTextStream capture stdout from xsltParseStylesheetFile

    And ....

    QString str;
    QTextStream in(stdin);
    function outputs ....
    in >> str;

    not grab nothing...! I am sure ... a method must exist....
    $content = file_get_contents("php://input");
    qt it must be able to read the stdin or stdout ecc...

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextStream capture stdout from xsltParseStylesheetFile

    Quote Originally Posted by patrik08
    not grab nothing...! I am sure ... a method must exist....
    $content = file_get_contents("php://input");
    Remember that C++ is not PHP and things in C++ not necessarily must work the same way as in PHP.

    Quote Originally Posted by patrik08
    qt it must be able to read the stdin or stdout ecc...
    It depends on what mechanism does xsltParseStylesheetFile() function use, because it certainly isn't a Qt function. You might try freopen().

  4. #4
    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: QTextStream capture stdout from xsltParseStylesheetFile

    Quote Originally Posted by jacek
    It depends on what mechanism does xsltParseStylesheetFile() function use, because it certainly isn't a Qt function. You might try freopen().
    Qt Code:
    1. QByteArray gocharxslt = DATA_CONVERTER.toAscii();
    2. freopen ("myfile.txt","w",stdout);
    3. printf ("This sentence is redirected to a file.");
    4. cur = xsltParseStylesheetFile( (const xmlChar*)gocharxslt.data() );
    5. qDebug() << "## say hello world ###.. ";
    6. fclose (stdout);
    To copy to clipboard, switch view to plain text mode 

    on myfile.txt found....
    Qt Code:
    1. This sentence is redirected to a file.
    To copy to clipboard, switch view to plain text mode 

    console ..... say ....
    Qt Code:
    1. file:///C%3A/convert.xml:1: parser error : parsing XML declaration: '?>' expecte
    2. d
    3. <?xml version="1.0" encoding="utf-8"?
    4. ^
    5. file:///C%3A/convert.xml:2: namespace error : Namespace prefix xsl on output is
    6. not defined
    7. <xsl:output method="html" encoding="utf-8"/>
    8. ^
    9. file:///C%3A/convert.xml:3: parser error : Extra content at the end of the docum
    10. ent
    11. <xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"/>
    12. ^
    13. error
    14. xsltParseStylesheetFile : cannot parse C:\convert.xml
    15. ## say hello world ###..
    To copy to clipboard, switch view to plain text mode 


    i suppose "xsltParseStylesheetFile" output is ... throw but is important to say on edit xslt file...

    if (!out.is_open())
    throw internal_fatal("can't open temporary file %s", fname.c_str());
    out << n;
    out.close();

    I found a other method same as a callback http://www.stylusstudio.com/xsllist/...post90770.html
    xsltSetGenericErrorFunc(cur,myhandler);

    Qt Code:
    1. void myhandler(void *ctx, const char *msg, ...) {
    2. qDebug() << "### start or no #### ";
    3. va_list args;
    4.  
    5. if (xmlGenericErrorContext == NULL)
    6. xmlGenericErrorContext = (void *) stderr;
    7.  
    8. va_start(args, msg);
    9. vfprintf((FILE *)xmlGenericErrorContext, msg, args);
    10. va_end(args);
    11. }
    To copy to clipboard, switch view to plain text mode 

    but not start....

    cur = xsltParseStylesheetFile((const xmlChar*)gocharxslt.data());
    xsltSetGenericErrorFunc(cur,myhandler);

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextStream capture stdout from xsltParseStylesheetFile

    Quote Originally Posted by patrik08
    I found a other method same as a callback
    So you want to capture stdout or stderr?

    Quote Originally Posted by patrik08
    but not start....
    Can you elaborate? What's happening and what did you expect to happen?

  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: QTextStream capture stdout from xsltParseStylesheetFile

    Quote Originally Posted by jacek
    So you want to capture stdout or stderr?
    Can you elaborate? What's happening and what did you expect to happen?
    stderr .... i want to show only on user the parse file error line ... throw i think is not possibel ....

    stdin grab null , stderr grab null...

    if i make an external qprocess to a xsltproc.exe param ecc i can grab and read all error and parser error.... ...
    and here no?
    The extarnal callback not start ... is possibel is a old version function...

    people normal not like to see error .... but on a xslt editor must debug all error and tag ....
    the list http://www.biglist.com/lists/xsl-list/archives/ have only 4 result by search
    xsltParseStylesheetFile



    Qt Code:
    1. QByteArray gocharxslt = DATA_CONVERTER.toAscii();
    2. QTextStream in(stderr);
    3. cur = xsltParseStylesheetFile( (const xmlChar*)gocharxslt.data() );
    4. in >> capturesdout; /* fill QString */
    5. qDebug() << "### xmlGenericErrorContext " << xmlGenericErrorContext;
    6. qDebug() << "## capturesdout ###.. " << capturesdout;
    7.  
    8. QByteArray gocharxslt = DATA_CONVERTER.toAscii();
    9. QTextStream in(stdin);
    10. cur = xsltParseStylesheetFile( (const xmlChar*)gocharxslt.data() );
    11. in >> capturesdout; /* fill QString */
    12. qDebug() << "### xmlGenericErrorContext " << xmlGenericErrorContext;
    13. qDebug() << "## capturesdout ###.. " << capturesdout;
    To copy to clipboard, switch view to plain text mode 

  7. #7
    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: QTextStream capture stdout from xsltParseStylesheetFile

    I continue post on c-programming ... why? problem is moore C and not QT

    http://www.qtcentre.org/forum/f-c-pr...qmap-2690.html

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextStream capture stdout from xsltParseStylesheetFile

    Quote Originally Posted by patrik08
    stderr .... i want to show only on user the parse file error line ... throw i think is not possibel ....
    It is possible, you have even found the right method --- use xsltSetGenericErrorFunc() function and write your own handler that will store all error messages in a QString or it will send them directly to the right widget. QString::sprintf() might come in handy.

  9. The following user says thank you to jacek for this useful post:

    patrik08 (18th June 2006)

  10. #9
    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: QTextStream capture stdout from xsltParseStylesheetFile

    Now i cann capture all error from xslt line nr.. tag ....bla bla....

    SUPER!

    is running so....

    Qt Code:
    1. /* class */
    2. void Gui_Front::Convert_Group()
    3. {
    4. QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
    5. bool fxml, fxslt, rfile;
    6. QString capturesdout;
    7. #if defined Q_WS_WIN
    8. QString disk_pre = QDir::homePath(); /* cat c: or d: ECC...*/
    9. QString disk = disk_pre.left(2);
    10. #define SHORTFILE \
    11. QString( "%1\\apache.xml" ).arg( disk ) /* window space name file trouble xslt */
    12. #define DATA_FILE_XML \
    13. QString( "%1\\data.xml" ).arg( disk )
    14. #define DATA_CONVERTER \
    15. QString( "%1\\convert.xml" ).arg( disk )
    16.  
    17. #else
    18. #define SHORTFILE \
    19. QString( "%1apache.xml" ).arg( WORK_CACHEDIR )
    20. #define DATA_FILE_XML \
    21. QString( "%1data.xml" ).arg( WORK_CACHEDIR )
    22. #define DATA_CONVERTER \
    23. QString( "%1convert.xsl" ).arg( WORK_CACHEDIR )
    24. #endif
    25. #define XSLTERRORFILE \
    26. QString( "%1ErMsgXSLT.dat" ).arg( WORK_CACHEDIR )
    27.  
    28. const char* params[5];
    29. params[0] = NULL;
    30. params[1] = NULL;
    31. params[2] = NULL;
    32. params[3] = NULL;
    33. params[4] = NULL;
    34.  
    35. qDebug() << "### SHORTFILE " << SHORTFILE;
    36. qDebug() << "### DATA_FILE_XML " << DATA_FILE_XML;
    37. qDebug() << "### DATA_CONVERTER " << DATA_CONVERTER;
    38. QString actualxslt = xsl_area->document()->toPlainText();
    39. fxslt = db->file_put_contents(DATA_CONVERTER,actualxslt);
    40. QString actualxml = xml_area->document()->toPlainText();
    41. fxml = db->file_put_contents(DATA_FILE_XML,actualxslt);
    42.  
    43. /* ######################################### */
    44. xsltStylesheetPtr cur = NULL;
    45. xmlDocPtr doc, outputDoc;
    46. xmlSubstituteEntitiesDefault(1);
    47. xmlLoadExtDtdDefaultValue = 1;
    48. /* ######################################### */
    49. char* xslt_errors;
    50. xsltSetGenericErrorFunc(&xslt_errors, qt_libxml_error_handler); /* error reg */
    51. xmlSetGenericErrorFunc (&xslt_errors, qt_libxml_error_handler);
    52. xsltSetGenericDebugFunc (&xslt_errors, qt_libxml_error_handler);
    53.  
    54. QByteArray gocharxslt = DATA_CONVERTER.toAscii();
    55. cur = xsltParseStylesheetFile( (const xmlChar*)gocharxslt.data() );
    56.  
    57. doc = xmlParseFile( QFile::encodeName(DATA_FILE_XML) );
    58. /*xsltSetGenericErrorFunc(doc, qt_libxml_error_handler);
    59.   xsltSetGenericDebugFunc(doc, qt_libxml_error_handler);*/
    60. outputDoc = xsltApplyStylesheet(cur, doc, params);
    61. xmlFreeDoc( doc ); /* free ram from xml! */
    62. doc = outputDoc; /* swap input and output */
    63. FILE* outfile = fopen( QFile::encodeName( SHORTFILE ), "w" );
    64. xsltSaveResultToFile( outfile, doc, cur );
    65. fclose( outfile );
    66. xsltFreeStylesheet(cur);
    67. xmlFreeDoc( outputDoc );
    68. xsltCleanupGlobals();
    69. xmlCleanupParser();
    70.  
    71. if (db->is_file(SHORTFILE)) {
    72. result_area->clear();
    73. result_area->insertPlainText(db->file_get_contents(SHORTFILE));
    74. result_area->toPlainText();
    75. }
    76. /*db->qt_unlink(SHORTFILE);*/
    77. /*qDebug() << "### xmlGenericErrorContext " << xmlGenericErrorContext;*/
    78.  
    79.  
    80. QApplication::restoreOverrideCursor();
    81. }
    82.  
    83. /* external function !*/
    84. void qt_libxml_error_handler(void *ctx, const char *msg, ...)
    85. {
    86. va_list args;
    87. QString message;
    88.  
    89. int size = 256;
    90. char * buf = new char[ size ];
    91.  
    92. while( 1 ) {
    93. va_start(args, msg);
    94. int retval = ::vsnprintf( buf, size, msg, args );
    95. va_end(args);
    96.  
    97. if( -1 < retval && retval < size ) { // everything was OK
    98. message = buf;
    99. /*if (!message.startsWith("error", Qt::CaseInsensitive)) {*/
    100. qDebug() << "### 1 error captured to insert on class as list or so.... " << message;
    101. /*}*/
    102. break;
    103. }
    104. else if( retval > -1 ) { // buffer too small
    105. size = retval + 1;
    106. delete [] buf;
    107. buf = new char[ size ];
    108. }
    109. else { // error
    110. // ...
    111. break;
    112. }
    113. }
    114.  
    115. delete [] buf;
    116. }
    To copy to clipboard, switch view to plain text mode 

  11. #10
    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: QTextStream capture stdout from xsltParseStylesheetFile

    Much tanks to jacek http://www.qtcentre.org/forum/u-jacek-7.html

    from This Thread is Been born a new sf.net projekt...

    A Visual xsltproc Debugger ....

    http://sourceforge.net/projects/visual-xsltproc/

Similar Threads

  1. Capture a keyboard event
    By mahe2310 in forum Qt Programming
    Replies: 8
    Last Post: 16th February 2006, 11:19

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.